Most taxpayers are totally unaware of the potential tax bill left behind when they foreclose on their home. In many cases, a homeowner believes that foreclosure might somehow end the financial misery associated with owning a home, but that is just not true. Nine times out of ten, the tax problem associated with a foreclosure results from the the lender forgiving some of the loan. This happens when the lender forecloses on the property and sells it for less than the outstanding mortgage. If there is a $100,000 mortgage and the home is only sold for $90,000, guess who is responsible for paying the tax on the $10,000 that was forgiven…that’s right: the borrower. The difference for which the borrower is no longer responsible is considered “cancellation-of-debt income” and is taxable income. Even though you aren't selling the house and the bank is, the IRS views the transaction as if you were the seller. That means in the end, you could owe taxes on the sale. I’m afraid this bad news comes directly from the IRS, via Publication 544:
"If you do not make payments you owe on a loan secured by property, the lender may foreclose on the loan or repossess the property. The foreclosure or repossession is treated as a sale or exchange from which you may realize gain or loss. This is true even if you voluntarily return the property to the lender. ... You figure and report gain or loss from a foreclosure or repossession in the same way as gain or loss from a sale or exchange. The gain or loss is the difference between your adjusted basis in the transferred property and the amount realized."
Another simplified example: You borrow $35,000 and default on the loan after paying back only $15,000. If the lender is unable to collect the remaining debt from you, there is a cancellation-of-debt of $20,000, which is generally taxable income to you. Bottom line: you can walk away but taxes bring you right back.