If you're not a real estate professional, the IRS counts the rent checks you get as passive income. That puts it in a separate category from wages or self-employment earnings. If your rental runs in the red, tax laws limit your ability to deduct such losses from your other income. By contrast, selling real estate does not result in passive income; rather, in results in a capital gain or loss.
When you sell a rental house, profits on the sale are capital gains, subject to capital gains tax. Your gain is roughly the difference between your purchase price, or "basis," and your sales price. You adjust the difference for upgrades and improvements: a $200,000 house with a $5,000 wiring upgrade and a $15,000 new roof has a $220,000 basis. That reduces your gain, which lowers your tax on the sale.
If you sell a rental property for less than the basis, you can write off your loss. Figure the loss on Form 4797 for the sale of business property and then report the result on your 1040. You can deduct up to $3,000 this year, or $1,500 if you file a joint return. If you have, say, a $12,000 loss, you deduct $3,000 this year and carry $9,000 forward to next year. You deduct that from next year's income, carry any leftovers forward, and so on.
Passive and Capital
Although capital gains income isn't passive income, you can sometimes deduct rental losses against it. The year you sell the rental, you get to deduct the year's passive losses against your non-passive income. This only works if you report all the gain or loss from the sale in that year, rather than carrying a loss forward. Giving the house away, converting it to your personal home or swapping it for another house don't give you the same passive-loss tax break.
If you have more passive-activity losses than you can write off, you get to carry them forward, like capital losses. If you carry any passive losses forward to the year you sell the rental house, that's good news. Another special case in the tax code is that when you carry forward passive losses, you can write them off against capital gains, not just against passive income. This can reduce your taxable gain on the sale.