Legendary investor Warren Buffett, the CEO of Berkshire Hathaway (BRK-A, BRK-B), has made billions off investing in once beleaguered financial firms.

According to our estimates, Buffett has earned $18.71 billion on initial investments totaling $13 billion in Bank of America (BAC), Goldman Sachs (GS), and GE (GE).

Buffett invested in Bank of America as it dealt with legal troubles in 2011 related to mortgages, and he invested much-needed capital to Goldman and GE during the darkest hours of the 2008 financial meltdown.

These sorts deals reflect Buffett acting on his famed maxim: “Be fearful when others are greedy and greedy when others are fearful.”

But as Yahoo Finance’s Myles Udland notes, a closer look at these deals reveals that this is something only someone of Buffett’s investing caliber could ever accomplish.

Bank of America – $5 billion investment

Back in 2011, Bank of America was facing massive legal fines and settlements related to mortgage-backed securities and mortgages. Most were related to Countrywide Financial, which Bank of America bought in 2008.

That summer, Buffett called Bank of America CEO Brian Moynihan and let him know that the wanted to invest.

On August 25, 2011, the bank announced that Buffett snapped up $5 billion worth of its preferred stock that paid a 6% annual dividend. In other words, Bank of America would pay Buffett $300 million annually. This investment also came with warrants allowing him to buy 700 million common shares at $7.14 per share any time before Sept. 2, 2021.

In his 2016 annual shareholder Buffett wrote that if Bank of America — which offered a dividend rate of 30 cents at the time — increased its dividend rate above 44 cents before 2021, he would likely make the exchange from preferred shares to common.

This week, Bank of America said it plans to increase its quarterly dividend to 12 cents per common share, or 48 cents per share annually. And as expected, Buffett announced plans to exercise those warrants once the dividend rate increase takes effect.

Upon exchanging the preferred for common shares, Berkshire Hathaway will be Bank of America’s largest shareholder, with a position valued at just over $16.98 billion based on Friday’s closing price of $24.26. It would also make the position one of Berkshire Hathaway’s top five largest equity holdings, according to our estimates.

With a strike price of $7.14 and the stock closing $24.26 on Friday, Berkshire has made around $11.98 billion on paper on its initial $5 billion investment. Taking the $300 million annual dividend payments into consideration, Buffett has made another $1.725 billion.

Estimated return: $13.71 billion

Goldman Sachs – $5 billion investment

Of course, Bank of America is not the first investment in a struggling financial firm to result in a windfall for the Oracle of Omaha. In 2008, as the financial world was reeling from the collapse of Lehman Brothers, Buffett struck a deal with Goldman Sachs that was seen as a vote of confidence in the storied investment banking firm.

On September 23, 2008, Goldman announced that it would sell Buffett $5 billion worth of preferred stock that also paid a 10% dividend. Goldman would pay Buffett $500 million annually. The preferred stock was redeemable at any time but at a 10% premium. As part of the deal, Buffett received warrants to purchase $5 billion of common stock with a strike price of $115 per share that would be exercisable anytime over the next five years.

View photos Goldman Sachs chairman and CEO Lloyd Blankfein REUTERS/Jonathan Ernst More

Berkshire clearly enjoyed the dividend payment. Breaking it down, $500 million per year works out to be over $1.4 million per day, $57,077 per hour, $951 per minute, and $15 per second.

But Buffett knew that wouldn’t last long.

“Goldman Sachs has the right to call our preferred on 30 days notice, but has been held back by the Federal Reserve (bless it!), which unfortunately will likely give Goldman the green light before long,” Buffett wrote in the 2010 shareholder letter.