Some people in this predicament are fighting the I.R.S. and winning. Sometimes, lower payments can be negotiated with the I.R.S., tax experts say.

In other cases, bankruptcy or a claim of insolvency can eliminate the tax burden. Sometimes, the bills are sent out erroneously, as banks fail to keep track of home values and what price the properties ultimately sell for.

“The tax laws are far too complex for borrowers to understand,” said Kurt Eggert, a professor at Chapman University School of Law, noting that there are distinctions between selling a house for less than the loan amount and losing one in foreclosure. He says it is crucial to get expert tax advice to sort through the bewildering complications.

The whole concept can be counterintuitive. “Your home has declined in value and you lose it,” Mr. Eggert said. “Then the I.R.S. says you owe tens of thousands in taxes because you got a windfall when the debt was forgiven.”

Mr. Stout has suffered doubly from the downturn in the housing market. He earned $65,000 last year as a salesman for a roofing company. But last winter, his job was cut from a salaried position to an hourly one. Then his hours were reduced, as construction demand eased. Through July he had earned only $25,000, said his lawyer, Stephen G. Doherty, of Bennett & Doherty in Doylestown, Pa., putting him on pace for a pay cut over all this year.

Mr. Doherty set out to appeal the Stouts’ tax bill by arguing that Wells Fargo got the home as collateral so the family did not reap a benefit. The Stouts and their lawyer also hoped to show that Wells Fargo was able to sell the house for far more than $1. Finally, they contended that penalties were inappropriate because they did not receive a tax notice in 2005 or 2006.

Image Agnes Mouser, a 65-year-old widow in Texas, received a $10,000 tax bill after foreclosure on her loan to pay off credit-card debt. Credit... Michael Stravato for The New York Times

After a reporter inquired about the Stout matter, Wells Fargo Home Mortgage said last week that it had reviewed the Stouts’ tax documents and was filing a corrected 1099 tax form to show that no debt had been canceled, because the fair market value of the home was actually more than Mr. Stout had owed.