The Federal Housing Finance Agency (FHFA) sure does seem to be making a lot of money from settlements lately. In fact, after Bank of America's (BAC 1.70%) recent $9.3 billion deal, the agency has now settled 10 of the 18 lawsuits it filed related to the sale of mortgage securities leading up to the financial crisis. Just how much money are we talking here, and where is it going? How badly will it hurt the banks? Here's a breakdown of the ongoing FHFA legal saga and how it could affect your wallet.

How much are we talking about so far?
As I already mentioned, the Bank of America settlement is the 10th related to the sale of private-label mortgage securities to Fannie Mae (FNMA 1.47%) and Freddie Mac (FMCC 3.41%) in the pre-crisis years. 

So far this year, in addition to Bank of America's $9.3 billion, Morgan Stanley ($1.3 billion), Credit Suisse ($885 million), and Societe Generale ($122 million) have also reached settlements. In all, the settlements so far total over $19 billion.

This is good for Fannie and Freddie's stockholders, right? Not so fast...
This money technically goes to Fannie and Freddie, but it effectively goes to the U.S. taxpayers to repay the $188 billion bailout the two agencies received in 2008. As part of the bailout, the Treasury Department bought preferred stock in Fannie and Freddie, which requires the agencies to pay a dividend. However, Fannie and Freddie are not allowed to repay the principal amount, unlike the Treasury's arrangement with the banks it bailed out.

Up until about a year ago, the Treasury collected 10% dividend payments, but the agreement has since been modified to also gain most of the agencies' profits. While shareholders in Fannie and Freddie are furious, unless they succeed in suing for a cut of the dividends, they will most likely never see any profit from the arrangement. As for the proceeds of the FHFA lawsuits, they will be treated as profit, and therefore will go the way of the dividends -- to the Treasury.

The total dividends paid to the Treasury are in the $150 billion range now, so it appears taxpayers will be made whole and then some.

Won't this destroy the banks' profits?
Ultimately, the banks have planned for this, and it was no surprise. In other words, they all stashed a lot of cash in reserve in order to cover any fallout from the financial crisis: settlements, loan losses due to bad mortgages, and more. So, in all of these cases, the banks had already planned for this expense and then some, and won't see their profits destroyed.

Now, this is not necessarily the case for the holdouts like Goldman Sachs and HSBC Holdings. According to the FHFA complaint, Goldman sold $11.1 billion in mortgage-backed securities to Fannie and Freddie. So far the trend seems to be settling for about 13% of this amount, which in Goldman's case would mean just over $1.4 billion. However, if Goldman decides not to settle, the case will go to trial, and all bets are off. There are trial dates scheduled in September for Goldman and HSBC, and while I would expect the banks to settle, it is far from certain yet.

How to play it
As these banks settle, it takes a huge lingering burden off their shoulders. In Bank of America's case, it was the largest headache still left from the crisis, and with most of their legal drama behind them, the company can move on and focus on the future.

As these settlements continue to roll in, the banks are a buying opportunity on any price weakness. Virtually the entire sector is trading at historically low valuations, and the main reason for this is the uncertainty surrounding the banks. Settling cases like these helps to eliminate uncertainty, and the valuations of these companies should rise accordingly as the crisis drama finally dissolves.