The Internal Revenue Service is battling the Federal National Mortgage Association -- a former federal agency that still enjoys preferential treatment from the government -- over a $666 million tax writeoff the association took for what the IRS says was an $875 expenditure.

In one of the largest U.S. Tax Court cases ever tried, the IRS says the mortgage association, known as Fannie Mae, owes $320 million in taxes as a result of a series of improper mortgage-loan exchanges and refinancing agreements. Another $200 million is owed separately, the IRS says, by savings and loans that participated in the deals with Fannie Mae. The Fannie Mae case is expected to set a precedent for those cases too, the IRS said.

"When all was said and done, Fannie Mae spent $875 . . . , and the Treasury was out approximately half a billion dollars," IRS trial attorney Kendall C. Jones said during opening arguments in the trial, which began in U.S. Tax Court yesterday.

Altogether, as much as $1 billion in taxes may be at stake when other similar transactions are added to the Fannie Mae tax writeoffs, IRS officials said. If many S&Ls have to pay significant amounts of back taxes, it could put a heavy strain on the ailing industry, experts say.

The IRS filed a deficiency notice for the contested taxes in April 1986; Fannie Mae paid some $200 million and then filed suit against the IRS to recover the money and an additional amount it said it was owed as a refund.

The deals, carried out by Fannie Mae in the early 1980s, were made possible by regulators at the Federal Home Loan Bank Board, which changed its rules so that the transactions would not be recorded as losses for accounting purposes, even though they were generating large tax losses. As a result of the ruling by the bank board, Fannie Mae and the S&Ls posted profits when they might otherwise have had losses.

The IRS is seeking to prove tax breaks were the only motivation for the deals. Fannie Mae officials do not deny that they entered into the swap arrangements with tax benefits in mind, but they say there were legitimate business reasons as well. On the stand yesterday, Robert J. Mahn, Fannie Mae senior vice president and controller, called the $875 figure "ludicrous," saying costs of the program were much higher, but could not be calculated.

Fannie Mae, a congressionally chartered corporation, buys mortgages from S&Ls. It then sells securites backed by the loans, freeing up funds for additional mortgage lending.

In 1968, Congress converted Fannie Mae from a federal agency into a for-profit, tax-paying company whose stock is traded on the New York Stock Exchange. Headquartered on Wisconsin Avenue NW, Fannie Mae is the nation's largest investor in residential mortgages and borrows more money than any other organization in the nation, except the federal government.

Fannie Mae enjoys a few special benefits from its former association with the federal government: It can borrow money at lower interest rates than private institutions can, and it can call on the U.S. Treasury for a loan in times of dire need. Fannie Mae also is exempt from many of the reporting requirements of the Securities and Exchange Commission.

The complex mortgage-swap transactions at issue in the tax case were undertaken by Fannie Mae in 1980 and 1981, when rising interest rates left the corporation holding a large portfolio of mortgages on which it was receiving low rates, while it had to borrow money at higher rates. It was losing as much as $1 million per day.

One of the ways Fannie Mae dealt with the situation -- which also caused large losses in the S&L industry -- was to exchange partial ownership in a group of the mortgages it held for a similar group of mortgages held by about 50 other financial institutions.

The IRS contends the mortgages disposed of were similar to the mortgages that replaced them: the interest rates and the terms of the loans were the same. And all the loans were worth less than their face value -- a $100,000 mortgage, for instance, might have been actually valued at $60,000 or $70,000 -- because of the interest differential.

If Fannie Mae had sold the loans outright, it would have taken a significant financial loss. But because they were exchanged for a similar group of mortgages, Fannie Mae instead only took a tax loss, reflecting the acquisition of a below-market pool of loans. During the years in question, the tax loss claimed was $265 million. The $875 figure represents the difference in value between the pools of mortgages that were exchanged.

The exchange also permitted the S&Ls on the other side of the transaction to take similar tax losses in return for acquiring the below-market Fannie Mae mortgages, losses the IRS said totaled about $200 million. Most of those losses are being contested in other pending tax cases, according to Jones, the IRS lawyer.

As part of the Fannie Mae tax court case, the IRS also is contesting another $341 million in losses that Fannie Mae claimed as part of a program involving loan refinancings. In these cases, Fannie Mae induced S&Ls to persuade homeowners with low-interest mortgages to refinance, then bought the new mortgages from the S&Ls.

Fannie Mae first recorded the purchases as a payoff of the old mortgage -- which would not produce a tax writeoff -- then changed its position and treated the purchases as a swap for tax purposes. Fannie Mae contended a loss occurred because the new mortgages were bought at prices below full value.

The IRS says Fannie Mae owes $156 million in back taxes due to losses it should not have taken, and also is not entitled to tax refunds of $164 million, as a result of both the swap transaction and the refinancing deals. The losses claimed in both types of deals total $666 million; tax liability on $60 million of the losses has been resolved.

Fannie Mae contends in court documents and in oral arguments that the exchanges were legitimate buy-and-sell transactions because the mortgages in the pools were not identical, but instead offered different degrees of risk, covered different kinds of properties and included homeowners of varying incomes. Also, Fannie Mae lawyers said, business reasons not related to taxes helped persuade the company to make the mortgage exchanges.

In a statement, Fannie Mae said the company believes its position defending the transactions is correct, but "if the tax court does not agree, an unfavorable determination would not have a material effect on the results of Federal National Mortgage Association as reported in its financial report."

Spokeswoman Charlotte Sterling said the company could not comment on the ethical issues raised by a firm that retains close ties to the federal government while taking large writeoffs to reduce its tax bill. "We feel it would be highly inappropriate for us to comment on the trial until the judge has made his decision," she said.