The tax rules for home sellers can be very complicated. They are summarized below, but you should also download IRA Publication 523, Selling Your Home, from the IRS web site: www.IRS.gov.
If you sell your primary residence at a profit, you may be able to exclude that profit from your taxable income. Unfortunately, you cannot deduct a loss from the sale of your main home. Worse, if you're contemplating abandoning your home or it is likely to be foreclosed, you need to check with a tax professional to see if you'll owe taxes as a result.
Here are the rules, in brief.
$250,000 or $500,000 exclusion on the sale of a primary residence.
Individuals can exclude up to $250,000 in profit from the sale of a main home (or $500,000 for a married couple) as long as you have owned the home and lived in the home for a minimum of two years. Those two years do not need to be consecutive. In the 5 years prior to the sale of the house, you need to have lived in the house as your principal residence for at least 24 months in that 5-year period.
You can use this 2-out-of-5 year rule to exclude your profits each time you sell or exchange your main home. Generally, you can claim the exclusion only once every two years. Some exceptions do apply.
Exceptions to the 2 out of 5 year rule. If you lived in your home less than 24 months, you may be able to exclude a portion of the gain. Exceptions are allowed if you sold your house because the location of your job changed, because of health concerns, or for some other unforeseen circumstance, like divorce or death.
Partial exclusion. You can exclude a portion of your gain if you are selling your home and lived there less than 2 years and you meet one of the above exceptions. You calculate your partial exclusion based on the amount of time you actually lived in your home. Here's how the exclusion is calculated: Count the number of months you actually lived in your home. Then divide that number by 24. Then multiply this ratio by $250,000 (if unmarried) or by $500,000 (if married). The result is the amount of gain you can exclude from your taxable income.
Calculating your cost basis and capital gain. The formula for calculating your cost basis on your main home is as follows:
State capital gain taxes. Depending on your state of residence, you may also need to consider state capital gains taxes. It's entirely possible that you can avoid federal taxes on the gain but still get whacked with state taxes.