The main way most homeowners avoid capital gains tax: the primary residence exclusion

If you have lived in the house as your main home for at least two of the last five years before you sell, you can exclude up to $250,000 of gain from your income if you are single, or $500,000 if you are married filing jointly. This is not a deduction — it means that portion of your profit is not taxed at all. The Internal Revenue Service (IRS) calls this the Section 121 exclusion.

You do not have to own the house for two consecutive years. You can have rented it out, lived elsewhere, and moved back in. What matters is that you lived there for 24 months total during the five-year window before the sale closes. If you meet this test, you report the sale on Form 8949 and Schedule D, but the excluded amount simply does not appear as taxable income.

This exclusion applies once every two years. If you sold a house two years ago and used the exclusion, you can use it again on a new sale now. If you sold less than two years ago, you cannot use it on your current sale unless you meet one of the IRS exceptions — such as a job relocation, health issue, or unforeseen circumstance.

Key Takeaways

  • The primary residence exclusion lets you exclude up to $250,000 (single) or $500,000 (married) of home sale profit from taxes if you lived there two of the last five years.
  • If your gain exceeds the exclusion amount, you owe capital gains tax on the remainder at either 0%, 15%, or 20% depending on your total income that year.
  • Timing your sale to fall in a lower-income year, bunching deductions, or donating appreciated shares instead of selling can reduce the tax you owe.
  • If you do not meet the two-year residence test, you may still reduce taxable gain by deducting home improvements, selling costs, and the cost basis of the original purchase.
  • Inherited homes receive a "step-up in basis," meaning heirs owe no capital gains tax on appreciation that happened before they inherited it.

What happens if your profit is larger than the exclusion

Suppose you bought for $300,000, made $100,000 in improvements, and sell for $800,000. Your gain is $400,000. If you are single and meet the residence test, you exclude $250,000, leaving $150,000 subject to capital gains tax. That $150,000 is taxed as a long-term capital gain (because you held the house more than one year).

Long-term capital gains rates are 0%, 15%, or 20% depending on your total taxable income for the year. A single filer in 2024 pays 0% if their income is under roughly $47,000, 15% if it is between $47,000 and $518,900, and 20% if it exceeds $518,900. These thresholds change yearly and are higher for married filers. The tax is calculated on your federal return; most states also tax capital gains, though a few do not.

The key point: your capital gains rate depends on your other income that year, not just the home sale. If you have a low-income year — you retired, took unpaid leave, or had business losses — your capital gains may fall into the 0% or 15% bracket instead of 20%.

Timing the sale to reduce your tax bracket

Because capital gains tax depends on your total income, you can sometimes reduce what you owe by controlling when you sell. If you are retiring mid-year, selling the house in the year you retire (when your income is lower) may put the gain into a lower tax bracket than selling it the following year when you have a full year of retirement income or pension payments.

Similarly, if you have a year with large business losses, charitable donations, or other deductions that lower your taxable income, selling the house that year means your capital gains stack on top of a lower base. The math is worth running with a tax preparer, especially if the gain is over $200,000.

This strategy works only if you control the timing. If you need to sell quickly due to a job move or health issue, you cannot wait for a better tax year. But if you have flexibility — selling in six months versus next year — a conversation with a CPA about your income that year can save thousands.

Deductions and costs that reduce your taxable gain

Your taxable gain is the sale price minus your adjusted cost basis. Your basis starts with what you paid for the house, plus the cost of major improvements (a new roof, foundation work, kitchen renovation). It does not include maintenance or repairs (painting, fixing a leak). The IRS distinguishes between improvements that add value and repairs that keep the house in working order.

You also subtract the cost of selling: real estate agent commissions, title insurance, attorney fees, and transfer taxes. These are not deducted separately on your tax return; they reduce the sale price, which lowers your gain. Keep receipts and closing statements that show these costs.

If you made improvements over the years, gather the invoices and receipts. A $50,000 kitchen renovation or $30,000 roof replacement adds to your basis and reduces your taxable gain dollar-for-dollar. If you cannot find receipts for old work, you cannot claim it, so this is worth organizing before you sell.

Using losses and income strategies in the year of sale

If you know you will have a large capital gain from the home sale, you can reduce your taxable income that year by accelerating deductions or realizing losses elsewhere. For example, if you have stock losses sitting in a brokerage account, selling those shares in the same year as the home sale lets you use the loss to offset the gain (up to $3,000 per year; excess losses carry forward).

You can also bunch charitable donations into the year of the sale if you itemize deductions. Instead of donating $5,000 per year, donate $15,000 in the sale year to lower your adjusted gross income. This works only if you itemize; the standard deduction is high enough that many people do not benefit from itemizing.

Another option: if you own appreciated securities (stocks, mutual funds) that you were planning to sell anyway, donate them to charity instead. You avoid capital gains tax on the appreciation and get a charitable deduction for the full current value. This is especially powerful if the securities have doubled or tripled in value.

Situations where you may not may have access to for the exclusion

You cannot use the primary residence exclusion if you have used it within the past two years on a different home. You also cannot use it if you did not live in the house for two of the last five years. Investors who rent out a property the entire time they own it, or who buy and flip houses, do not meet the residence test.

If you lived in the house for only one year before selling, you may still claim a partial exclusion if you sold due to a job relocation, health issue, or other unforeseen circumstance. The IRS publishes a list of may have access to reasons. You would exclude a fraction of the $250,000 or $500,000 based on how many months you actually lived there. A tax preparer can calculate this if your situation applies.

If you do not may have access to for the exclusion at all, your entire gain is taxable as a long-term capital gain (if you held the house over one year) or a short-term capital gain (if under one year). Short-term gains are taxed as ordinary income, which can be as high as 37% federally, plus state tax. This is why the two-year residence test matters so much.

What inherited homes and step-up in basis mean for your taxes

If you inherit a house, the IRS gives you a step-up in basis. This means your cost basis is reset to the fair market value of the house on the date the previous owner died, not what they originally paid for it. If your parent bought the house for $200,000 and it was worth $600,000 when they died, your basis is $600,000. If you sell it immediately for $600,000, you have zero gain and owe no capital gains tax.

This step-up applies to most inherited property and is one of the largest tax breaks in the code. It means appreciation that happened during the previous owner's lifetime is never taxed. You only owe capital gains tax on appreciation that happens after you inherit it. If you inherit and hold the house for two years before selling, you may also may have access to for the primary residence exclusion if you lived there during that time.

Frequently Asked Questions

Do I have to pay capital gains tax if I sell my house at a loss?

No. If you sell for less than your adjusted basis, you have a loss, not a gain. You cannot deduct a personal home sale loss on your federal tax return. However, if you had rental income from the property, you may be able to claim the loss. Consult a tax preparer about your specific situation.

What if I lived in the house for only one year before selling?

You do not may have access to for the primary residence exclusion unless you meet one of the IRS exceptions (job relocation, health, unforeseen circumstance). Your entire gain is taxable. If you held the house over one year, it is taxed as a long-term capital gain. If under one year, it is taxed as ordinary income at your regular tax rate, which is usually higher.

Can I exclude capital gains if I rent out part of my house?

If you rented out part of the house during the time you owned it, the gain attributable to the rental portion is not covered by the exclusion. You must split the gain between the personal-use portion and the rental portion. Only the personal-use portion qualifies for the $250,000 or $500,000 exclusion. The rental portion is fully taxable.

Does my spouse have to live in the house for two years to claim the exclusion?

If you are married filing jointly, only one spouse needs to meet the two-year residence test. However, both spouses must not have used the exclusion on a different home within the past two years. If one spouse used it two years ago on a previous home, that spouse cannot use it again, but the other spouse can if they meet the requirements.

What records do I need to keep for the IRS?

Keep your original purchase documents, closing statement, receipts for home improvements, and the closing statement from the sale. The IRS does not require you to attach these to your return, but you must have them if audited. Keep them for at least three years after you file your return, or longer if you think an audit is possible.