Over the last three years, federal regulators have won giant legal settlements from companies like BP, Citigroup and JPMorgan Chase, but according to a new study, the outlines of those agreements have freed firms to write off billions as tax deductions.

The study by the United States Public Interest Group, a nonprofit advocacy group, examined the 10 largest settlements by five government regulators since 2012: the Department of Justice, the Securities and Exchange Commission, the Environmental Protection Agency, the Department of Health and Human Services and the Consumer Financial Protection Bureau.

In that time, companies were required to pay nearly $80 billion to resolve investigations into alleged wrongdoing, but the analysis found that companies “can readily write off at least $48 billion of this amount as a tax deduction.” That translates to a loss of $17 billion in federal tax revenue, more than what the Internal Revenue Service collects each year in estate taxes, according to the report.

At issue is the legal language of the deals and how they address what the authors call a “gray area” of the tax code. Corporations are allowed to deduct from their taxable income all ordinary and necessary business expenses. What they can’t do is deduct penalties or fines paid to the government. With large settlements, though, payments are often not a penalty or fine, but rather meant to address some form of liability connected to alleged misdeeds. When that’s the case, firms can typically write that amount off as a cost of doing business.

“It’s kind of a compromise,” said the report’s co-author, Michelle Surka, a tax and budget program associate at U.S. PIRG. “The corporation gets to ultimately deduct these huge amounts of payments, the government agency gets to advertise these huge top-line numbers saying that they’re holding the corporation accountable for its behavior, but the bottom line is that taxpayers are the ones who are losing.”

In 2013, for example, JPMorgan Chase agreed to what was then a landmark $13 billion civil penalty with the Department of Justice to resolve investigations into its sale of risky mortgages prior to the financial crisis. Of that amount, $11 billion was eligible for a tax deduction. A spokesman for the bank declined to comment.

Similarly, when the DOJ reached a $25 billion mortgage settlement in 2012 with Ally Financial, Bank of America, Citigroup, JPMorgan Chase and Wells Fargo, $20 billion of that amount was eligible as a deduction for the banks.

To be sure, the $48 billion highlighted in the study represents just the amount eligible for tax deductions. Because corporations do not have to report specifically how much they have deducted, or what they may deduct in future years, there is no way to definitively measure the actual amount deducted from past settlements. In 2013, though, the IRS noted that unless an agency explicitly forbids a company from doing so in a settlement, “almost every defendant/taxpayer deducts the entire amount” as a business expense. In other words, they have no incentive not to.

The study, which was released Thursday, noted that none of the five agencies have publicly available policies for the tax status of settlements, but it called the CFPB and the EPA the most consistent when it comes to ensuring that at least a part of all signed settlements can’t be tax deductible.

The DOJ signed the majority of the largest agreements analyzed, but only 18.4 percent of settlement dollars “were explicitly non-deductible,” according to the analysis. At the SEC, it was 15 percent.

Officials at the five agencies either did not respond or were unavailable for comment.

Federal law doesn’t require agencies to post information about settlements, but a bill that passed the Senate unanimously in September would require them to make available any agreement that they enter into with a company, and to provide a breakdown of how much is designated as a penalty or fine and not tax deductible. The measure, the Truth in Settlements Act, is currently stuck in the House.

“The reason why this issue matters is because when tax deductions are allowed for these settlement agreements, we’re forcing Americans to basically foot the bill and subsidize the corporate wrongdoing that these settlements are supposed to be addressing,” according to Surka. Moreover, she said, “When you tell a corporation that has committed some kind of crime, that it’s actions are business as usual, then recidivism is bound to happen.”