How to Avoid Capital Gains Tax on a Home Sale

You avoid capital gains tax on most home sales by qualifying for the IRS Section 121 exclusion, which lets a single filer exclude up to $250,000 of gain and a married couple filing jointly exclude up to $500,000 when the home was owned and used as a primary residence for at least two of the five years before the sale.

You avoid capital gains tax on most home sales by qualifying for the IRS Section 121 exclusion. A single filer can exclude up to $250,000 of gain, and a married couple filing jointly can exclude up to $500,000, when the home was owned and used as a primary residence for at least two of the five years before the sale. Gain above the exclusion is taxed as a long-term capital gain, and in some cases the 3.8% net investment income tax can also apply.

This guide walks through the ownership-and-use test, how gain is actually calculated, what happens when you do not meet the full test, and how the numbers flow into your tax return. The rules come from IRS Topic No. 701, IRS Publication 523, and IRS Topic No. 409, and the rate thresholds below reflect the 2026 inflation adjustments in IRS Revenue Procedure 2025-32.

The Section 121 exclusion in plain terms

Section 121 is the provision that keeps most homeowners from paying tax when they sell. It is not a one-time benefit, and you do not have to buy another home to use it. What matters is ownership, use, and timing. If you qualify, the excluded gain never appears as taxable income. You generally report the sale on your return, but the excluded portion is not taxed.

Two tests drive eligibility:

The two years do not have to be consecutive, and ownership and use can overlap. A married couple filing jointly can meet the ownership test if either spouse owns the home, but both spouses generally must meet the use test for the full $500,000 exclusion.

How the 2-of-5-year test works in practice

The five-year window is measured backward from the closing date. If you moved out, rented the home, or used it as a second home, that time still counts toward the window as long as the two years of qualifying use fall inside it. This is why a home you rented for a while and then moved back into can still qualify.

A few situations trip people up:

If you are close to the line, document your move-in and move-out dates before listing. Dates on utility bills, tax records, and your driver's license can matter if the IRS asks.

How taxable gain is calculated

Gain is not simply the sale price minus what you paid. The IRS formula is amount realized minus adjusted basis.

TermWhat it includes
Amount realizedThe sale price minus selling expenses such as commissions and certain fees you paid to sell.
Adjusted basisWhat you originally paid, plus capital improvements you made, minus any depreciation you claimed or could have claimed.
GainAmount realized minus adjusted basis. If the result is negative, you have a loss, which is generally not deductible on a personal residence.

Capital improvements are permanent additions or upgrades, like a new roof or an added room. Routine repairs and maintenance generally do not increase basis. Keeping a clean record of improvements is one of the simplest ways to reduce a future gain.

You can estimate your own numbers with the capital gains tax calculator and see the full picture with the home sale profit calculator. The capital gains exclusion reference summarizes the eligibility rules.

If you do not meet the full exclusion

Partial exclusions and exceptions exist for people who sold because of a change in employment, health reasons, divorce or separation, or certain unforeseen events. In those cases the IRS allows a reduced maximum exclusion, computed as a fraction of the full amount based on how long you met the tests. IRS Publication 523 explains the qualifying reasons and the math.

There is also a reduced exclusion for a home you used as a rental or second home before converting it to your primary residence. The exclusion is reduced by any depreciation taken after May 6, 1997, and non-qualified use can limit the amount you can exclude. This is one area where a tax professional earns their fee.

When the 3.8% net investment income tax applies

The net investment income tax, or NIIT, is a 3.8% surtax on the lesser of net investment income or modified adjusted gross income above $200,000 for single filers and $250,000 for married filing jointly. Those thresholds are not indexed for inflation. Taxable gain from a home sale can count as net investment income, so a sale with a large gain above the Section 121 exclusion can trigger the surtax for higher earners.

The exclusion comes first. Only the taxable gain that remains after Section 121 flows into the NIIT calculation. That is why documenting basis and improvements matters for sellers whose income is near the thresholds.

2026 long-term capital gains rates

Gain that exceeds your exclusion is taxed at long-term capital gains rates if you owned the home for more than a year. The 2026 brackets, per Revenue Procedure 2025-32, are:

RateSingleMarried filing jointlyHead of householdMarried filing separately
0%Up to $49,450Up to $98,900Up to $66,200Up to $49,450
15%Over $49,450 to $545,500Over $98,900 to $613,700Over $66,200 to $579,600Over $49,450 to $306,850
20%Over $545,500Over $613,700Over $579,600Over $306,850

These are the same thresholds that apply to other long-term capital gains, and they are based on taxable income, not gross income. See IRS Topic No. 409 for how gains and losses are reported.

Steps to reduce or avoid the tax

  1. Confirm you meet the two-of-five ownership and use test before you sell.
  2. Reconstruct your adjusted basis from your purchase documents and a list of capital improvements.
  3. Add up legitimate selling expenses that reduce the amount realized.
  4. Estimate the gain, then subtract the Section 121 exclusion you qualify for.
  5. Check whether your income puts you near the NIIT thresholds.
  6. Keep records of everything, and talk to a tax professional about your specific situation.

This page is general information, not tax or legal advice. Rules can change and outcomes depend on your facts. Verify current guidance with the IRS and a qualified professional.

Frequently asked questions

How long do I have to live in a home to avoid capital gains tax?

You generally need to have owned and used the home as your primary residence for at least two of the five years before the sale. The two years do not have to be consecutive. If you do not meet the test, a reduced exclusion may apply for certain qualifying reasons.

What is the difference between amount realized and adjusted basis?

Amount realized is the sale price minus selling expenses. Adjusted basis is what you paid, plus capital improvements, minus depreciation. Gain is amount realized minus adjusted basis, and only the gain above your Section 121 exclusion is taxable.

Can I use the Section 121 exclusion more than once?

Yes, but you generally cannot exclude gain from another home sale within two years before the current sale. Each sale must independently satisfy the ownership and use tests. Special rules apply to inherited homes and transfers between spouses.

Can I still owe tax if I qualify for the exclusion?

Yes. Gain above your exclusion limit is taxable at long-term capital gains rates, and the 3.8% net investment income tax can apply when your income exceeds the thresholds. Depreciation from a period as a rental can also reduce the exclusion.

How does the 3.8% NIIT work on a home sale?

It applies at 3.8% to the lesser of net investment income or modified adjusted gross income above $200,000 for single filers or $250,000 for married filing jointly. Taxable gain that remains after the Section 121 exclusion can count as net investment income.

Get matched with a local agent

Compare licensed agents in your area before you list. Free and no obligation.

Get Matched With an Agent →

Free and no obligation. You choose whether to work with any agent.

Cite this page

ListWithAgent Editorial Team. “How to Avoid Capital Gains Tax on a Home Sale.” https://listwithagent.com/learn/avoid-capital-gains-tax-on-home-sale/. Accessed 2026-09-12.

Sources

  • IRS Publication 523 — Selling Your Home — Internal Revenue Service — irs.gov
  • IRS Revenue Procedure 2025-32 — 2026 inflation adjustments (capital gains thresholds) — Internal Revenue Service — irs.gov
  • IRS Topic No. 409 — Capital Gains and Losses — Internal Revenue Service — irs.gov
  • IRS Topic No. 701 — Sale of Your Home — Internal Revenue Service — irs.gov
  • IRS — Net Investment Income Tax — Internal Revenue Service — irs.gov

Every figure and rule on this page traces to the official publishers above. See our methodology.

Not a brokerage and not advice. List With Agent is not a real estate brokerage. We are an independent marketing and referral service that connects home sellers with licensed real estate agents. This page is general educational information, not legal, financial, or real estate advice.

By the ListWithAgent Editorial Team. Last updated 2026-09-12. Educational information only — not legal, financial, or real estate advice.