Bank of America is close to reaching a record $16 billion to $17 billion settlement with the U.S. Justice Department over toxic mortgages issued by its Countrywide Financial unit and other mortgage lenders it acquired.

The bank has reportedly agreed to pay out some $9 billion of the settlement in cash to the U.S. government, as well as states and others, according to various media reports. The remainder of the money would be set aside for helping out homeowners who have yet to recover from the housing crash.

Countrywide, a leading lender during the housing boom, originated or bought about $1.4 trillion in mortgages between 2005 and 2007. Bank of America acquired the Calabasas firm in 2008.

The settlement comes as the federal government has sought to crack down on banks that performed irresponsibly leading up to the financial meltdown of 2008. They are accused of issuing mortgages that borrowers were unable to pay, and then selling the loans in securitized packages to investors. If the deal is finalized, it would represent the largest settlement ever reached between the government and a company, topping the $13 billion deal between the U.S. and J.P. Morgan Chase late last year.

The majority of the loans in question were from Countrywide, while Merrill Lynch and First Franklin Financial Group, both also now Bank of America subsidiaries, are also involved.

Last week, U.S. District Judge Jed Rakoff in New York levied a $1.3 billion judgment against the Charlotte, N.C. bank, stemming from an October decision that found the bank liable for loans sold by Countrywide prior to its acquisition.

At the center of that decision was the Countrywide program known in the industry as “The Hustle,” which focused on incentivizing mortgage loan officers to churn out mortgages quickly, not really considering the mortgage holders’ ability to repay the loans.

The fine was based on the amount of losses incurred by investors in the loans, including government-sponsored mortgage operations Fannie Mae and Freddie Mac.

Including a previous settlement with Fannie and Freddie of nearly $6 billion, the total tab for Bank of America could add up to more than $24 billion.

Shares fell 8 cents, or a fraction of 1 percent, to $15.12 on the New York Stock Exchange.