With hundreds of thousands of homeowners having negotiated loan modifications or short sales or been foreclosed upon during the past year, the Internal Revenue Service has issued fresh guidance on how to handle canceled mortgage debt in the coming tax season.

When most debts are canceled by a creditor, such as unpaid balances on student loans or credit cards, the forgiven amounts are treated as ordinary, taxable income by the Internal Revenue Code. But under a special exemption adopted by Congress covering distressed home mortgages, many owners can escape the ultimate double-whammy: getting kicked while you're down and hit with extra taxes because your mortgage went seriously delinquent or you lost your house.

In its latest guidance, the IRS focuses on several key points that owners - and former owners - need to know. Tops on the list: Just because a lender wrote off a portion of your mortgage debt, this doesn't mean you automatically qualify for special tax treatment. To the contrary, there are essential tests you need to pass to qualify. The debt your lender canceled must have been used by you "to buy, build or substantially improve your principal residence."

There's a lot packed into these words, so it's important to parse them carefully. Start with the house itself. It can't be your second home, an investment condominium, a weekend retreat or a seasonal home you occupy for less than half the year. It can only be your main residence, and fully documented as such.

Next, the unpaid mortgage balance your lender canceled as part of a modification, short sale or foreclosure cannot have been used for non-qualifying purposes (i.e. for something other than acquiring or constructing the house or making capital improvements to it). Refinanced mortgage debt used for kids' tuition, vacations, buying cars or paying off credit card bills won't make the grade.

The IRS offers a hypothetical example of how borrowers can mess up their chances for tax relief. A taxpayer took out a first mortgage of $800,000 when he purchased his home years ago. Thanks to strong appreciation in property values, the house was soon worth $1 million, and the owner refinanced the mortgage to $850,000. The loan balance at the time of the refinance was down to $740,000, and the owner used the $110,000 in cash-out proceeds to buy a new car and pay off credit card debts.

Bad move. A year or two later - presumably well into the recession and housing bust - the home value had plunged to between $700,000 and $750,000. The owner then persuaded his bank to allow a short sale for $735,000 and cancel the remain-ing $115,000 of unpaid debt.

Does the owner get tax relief on the full $115,000 under Congress's special exemption? No way, according to the IRS. He escapes income taxes on just $5,000 of the $115,000 because he spent the other $110,000 on a car and credit card balances - neither of which counts as "qualified principal residence" debt.

Greg A. Rosica, a tax partner with accounting giant Ernst & Young, says misunderstandings over the rules about mortgage-debt forgiveness are "commonplace." People often don't know that "the equity line [money] you used for vacations" and other purposes "just will not qualify" under IRS rules.

Taxpayers who walk away from their houses may be liable for taxes, Rosica said in an interview, if at some point the property "no longer was their primary residence." This could happen, for example, if they rented it out for the period between their last payment and the foreclosure, effectively converting the house into rental property, not their principal home.

The IRS highlighted some other key points in its guidance:

lMortgage cancellation relief is capped at $2 million for married and single taxpayers, $1 million each for married owners filing separately.

lAnyone who has had mortgage-debt cancellation as part of a loan modification or foreclosure should go to IRS.gov and download Form 982 and IRS Publication 4681 for additional filing details. Alternatively, they can call 800-TAX-FORM to request copies.

lLenders who write off unpaid mortgage balances typically provide borrowers with a year-end IRS Form 1099-C cancellation of debt statement, including the amount of the loan forgiven and the fair market value of the property. If you've had mortgage debt canceled but have never received a 1099-C from your lender, get in touch and request it if you want to avoid federal tax hassles.