Verified against IRS Topic 701 and Pub 523

How to Avoid Capital Gains Tax on a Home Sale

By the lazysmirk team · Published Jul 12, 2026
Quick answer

The main tool is the Section 121 exclusion: if the home was your primary residence, you can exclude up to $250,000 of gain from tax ($500,000 for married couples filing jointly). To qualify you must have owned the home and lived in it as your main home for at least 2 of the last 5 years before the sale; the two years do not need to be continuous. One correction up front: buying another house with the proceeds does nothing. That "rollover" rule was repealed in 1997, and the exclusion replaced it.

  • The Section 121 exclusion shields $250,000 of gain (single) or $500,000 (married filing jointly) on a primary residence you owned and lived in for 2 of the last 5 years. It can be used once every 2 years, and the amounts are unchanged for 2026.
  • Your taxable gain is the sale price minus selling costs minus your adjusted basis: purchase price plus documented capital improvements. Every receipt for an addition, roof, or remodel reduces the gain dollar for dollar, which makes basis the most under-used lever.
  • Reinvesting the proceeds in another home does not avoid the tax; that rule died in 1997. And a rental cannot be fully laundered through 2 years of residence: post-2008 rental years stay taxable pro rata, and depreciation is always recaptured.

The Section 121 exclusion: the headline tool

Section 121 of the tax code lets you exclude up to $250,000 of gain on the sale of your main home if you file single, or up to $500,000 if you are married filing jointly. Excluded means gone: it is not deferred, not spread out, simply never taxed. These amounts were set by the Taxpayer Relief Act of 1997 and have never been indexed for inflation, so they are the same for 2026 (IRS Topic 701 and Publication 523 are the source documents).

Three tests decide whether you qualify:

  • The ownership test: you owned the home for at least 2 years (24 months) out of the 5 years ending on the sale date.
  • The use test: you lived in the home as your main residence for at least 2 years out of those same 5 years. The 24 months do not need to be continuous, and the ownership and use periods do not need to overlap. You can even have rented the home to someone else for part of the window, or rented it from the owner before you bought it.
  • The once-every-2-years rule: you cannot have excluded gain on another home sale in the 2 years before this one.

For the full $500,000, both spouses must meet the use test and neither can have used the exclusion in the past 2 years, but only one spouse needs to meet the ownership test. If only one spouse qualifies on use, the couple can still exclude that spouse's $250,000.

Most home sellers never owe a dime because of this rule: the median seller's gain sits well under the exclusion. The rest of this guide is for everyone whose gain is bigger, whose tenure is shorter, or whose home spent time as something other than a primary residence.

What the exclusion saves: a worked example

A married couple bought their home for $350,000 and sells it for $900,000. Their gain is $550,000. They lived in it well past the 2-year mark, so the full $500,000 exclusion applies:

Worked example: bought at $350,000, sold at $900,000, 15% long-term rate
Without the exclusionWith the Section 121 exclusion
Gain on sale$550,000$550,000
Exclusion$0$500,000
Taxable gain$550,000$50,000
Federal capital gains tax (15%)$82,500$7,500

The exclusion turns an $82,500 tax bill into $7,500, a saving of $75,000. The 15% rate holds as long as the couple's total taxable income, including the $50,000 taxable slice of the gain, lands between $98,900 and $600,050 (the 2026 joint thresholds); below $98,900 the rate is 0%, above $600,050 it is 20%. You can see exactly where a taxable gain stacks on top of your other income with the federal income tax calculator.

Now the squeeze: the identical house, but a single owner. The exclusion drops to $250,000, so $300,000 of the same $550,000 gain is taxable, roughly $45,000 of tax at 15%. And because a gain that size pushes modified adjusted gross income past $200,000, the 3.8% net investment income tax applies to part of it too. Same house, same gain, a five-figure difference in tax purely from filing status. This is why the timing rules for widowed and divorcing sellers in the special-situations section matter so much.

Grow your basis: the most under-used lever

The gain is not "sale price minus what you paid." It is sale price, minus selling costs, minus your adjusted basis: the purchase price plus everything you spent on capital improvements over the years, plus certain closing costs from when you bought (title fees, legal fees, transfer taxes, survey costs). Selling costs count too: the agent commission, closing costs you pay as the seller, even qualifying staging and marketing costs come off the sale price.

The rule that decides what counts: a capital improvement adds value, prolongs the home's life, or adapts it to new uses, and it raises your basis. A repair just keeps the home in ordinary operating condition, and it does nothing for your taxes.

Improvements vs repairs (IRS Publication 523)
Raises your basis (improvement)Does not count (repair or maintenance)
Room addition, finished basement, new deck or porchInterior or exterior painting
Full roof replacementPatching a leak or replacing a few shingles
New HVAC system, furnace, or water heaterServicing or repairing the furnace
Kitchen or bathroom remodelFixing a leaking faucet or a broken window pane
New windows, insulation, rewiring, plumbing upgradesReplacing a cracked outlet or a section of pipe
Driveway, fence, in-ground pool, major landscapingLawn care, gutter cleaning, pest control

One nuance: a repair done as part of a larger remodel counts with the remodel. Replacing the broken window is a repair on its own; replacing every window in the house is an improvement.

The numbers are worth the shoebox of receipts. The single filer from the example above, with $300,000 of taxable gain, digs out documentation for $80,000 of improvements made over 20 years of ownership: the roof, the HVAC, the kitchen, the deck. Basis rises by $80,000, taxable gain falls by $80,000, and at the 15% rate that is $12,000 of tax erased by paperwork alone.

So the ritual: keep a folder (paper or digital) for every invoice, permit, and contractor receipt from the day you buy. Reconstructing 20 years of improvements the week before closing is nearly impossible; collecting them as you go is trivial. And remember the distinction between equity and gain: paying down the mortgage builds equity but does nothing to your basis or your gain. The home equity calculator tracks the first number; this section is about the second.

Sold before 2 years? The partial exclusion

Failing the 2-year tests does not always mean losing the whole exclusion. If the main reason you sold early was a work move, a health issue, or an unforeseeable event, you get a reduced exclusion, pro-rated by how much of the 2 years you completed. The qualifying reasons in Publication 523:

  • Work: you (or a spouse or co-owner) took a new job, or were transferred, to a location at least 50 miles farther from the home than the old job was.
  • Health: the move was to obtain, provide, or facilitate treatment for a disease, illness, or injury, for you or a family member (a doctor's recommendation to relocate qualifies).
  • Unforeseen circumstances: events you could not reasonably have anticipated before buying: death, divorce or legal separation, twins or other multiple births, job loss that qualifies you for unemployment, a change in employment that leaves you unable to pay basic living costs, or the home being destroyed or condemned.

The formula pro-rates the exclusion cap, not your gain. Take the shortest of your ownership time, your residence time, and the time since you last used the exclusion, divide by 24 months, and multiply by the full exclusion. Live in the home 12 months before a qualifying 500-mile job transfer and you keep 12/24, which is half: up to $125,000 of gain excluded single, $250,000 married filing jointly.

Because the cap is what gets cut, not the gain, the partial exclusion is more generous than it sounds. A home rarely gains more than $250,000 in a year, so a qualifying couple selling after 12 months usually still pays nothing. What does not qualify: simply wanting a bigger house, a better school district, or a profit. Sell early for a non-qualifying reason and the full gain is taxable, at short-term ordinary rates if you owned the home a year or less.

Special situations: widowed, divorced, military

Widowed sellers get a 2-year window to keep the full $500,000. A surviving spouse who sells within 2 years of their spouse's death can still claim the joint $500,000 exclusion, provided they have not remarried and the couple met the ownership and use tests before the death. Wait past the 2-year mark and the exclusion drops to the single filer's $250,000: on the worked example above, that deadline alone is worth $37,500 in tax. There is a second cushion: the deceased spouse's half of the home receives a stepped-up basis to its value at death (the full home steps up in community property states), which often shrinks the gain dramatically on its own. Step-up is covered in depth in our guide to inheritance taxes.

Divorce transfers carry the clock with them. If your ex transferred the home to you as part of the divorce, you are treated as having owned it for as long as they did. And if the divorce decree lets your ex live in the house while you stay on the title, their time living there counts as your use, so the spouse who moved out does not forfeit the exclusion when the house finally sells.

Military, Foreign Service, and intelligence personnel can pause the clock for up to 10 years. Time on qualified official extended duty (stationed at least 50 miles from the home, or living in government quarters under government orders, for more than 90 days) can be elected to suspend the 5-year test period. The lookback window can stretch to 15 years, so a servicemember who lived in the home for 2 years, then spent a decade of postings elsewhere, can still sell with the full exclusion.

Rentals, home offices, and depreciation recapture

Depreciation always comes back. If you ever claimed depreciation on the home, for a rental period or a home office, the exclusion never covers the gain attributable to depreciation claimed after May 6, 1997. That slice is taxed as unrecaptured Section 1250 gain at your ordinary rate, capped at 25%, even if the rest of the gain is fully excluded. A home office inside your dwelling does not split the exclusion itself (the residence is still one property), but the depreciation you deducted for it is recaptured all the same. This is a repayment of deductions you already benefited from, not a penalty, but it surprises sellers every year.

You cannot fully launder a rental through 2 years of residence. Before 2009 you could rent a property out for years, move in for 2, and exclude the whole gain. The 2008 housing law closed that door with the nonqualified use rule: for periods after 2008 when the home was not your main residence before it became your residence, the gain is split pro rata by time, and the nonqualified share can never be excluded.

The arithmetic: you buy a property and rent it out for 6 years, then live in it for 2 years and sell with a $200,000 gain. You pass the 2-of-5 tests, but 6 of your 8 ownership years are nonqualified use, so only 2/8 of the gain ($50,000) is even eligible for the exclusion. The other $150,000 is taxable no matter what, and the depreciation you claimed during the rental years is recaptured on top. The conversion still helps, it just no longer erases everything.

The rule is one-directional, and the direction favors ordinary movers: time after you move out of your main home does not count as nonqualified use within the 5-year window. Live in your home for years, move out, rent it for up to 3 years, and sell: the full exclusion still applies (though the rental-period depreciation is still recaptured).

What does not work

The "reinvest the proceeds" myth. Buying another house with the sale money does nothing to your tax bill. Full stop. The old Section 1034 "rollover replacement residence" rule, which deferred gain if you bought a pricier home within 2 years, was repealed in 1997, along with the old one-time $125,000 over-55 exclusion. Both were replaced by the Section 121 exclusion. Nearly thirty years later, this remains the single most repeated piece of dead tax advice at open houses. Where the proceeds go, a bigger house, an index fund, a boat, is irrelevant; what matters is the gain, the exclusion, and your basis records.

A 1031 exchange is for investment property, not your home. Swapping into another property to defer gain under Section 1031 requires that both properties be held for investment or business use. Your primary residence does not qualify, period. Where 1031 genuinely enters the picture is a rental property: an investor can exchange a rental for another rental and defer the gain, and in carefully structured cases a property can move between 1031 treatment and Section 121 treatment over many years (with the nonqualified-use pro-ration above applying). That is specialist territory with real holding-period requirements; if a promoter pitches a 1031 for the house you live in, walk away.

Reporting the sale (often you do not have to)

If your entire gain is excluded and you did not receive a Form 1099-S from the closing agent, the sale does not go on your tax return at all. At closing you can sign a certification that you qualify for the full exclusion, which is what allows the agent to skip issuing the 1099-S, so speak up before closing, not after.

You must report the sale on Form 8949 and Schedule D if any of these apply: you received a 1099-S (report it even if the gain is fully excluded, so the IRS can match the form), part of the gain is taxable, you have depreciation to recapture, or you choose not to claim the exclusion (occasionally worth it to save the exclusion for a bigger sale within 2 years). One asymmetry to know: a loss on your personal residence is never deductible.

Two short lines to finish. State taxes: most states with an income tax follow the federal exclusion, but they tax any remaining gain at ordinary state rates with no preferential capital gains rate, so check your state before counting the savings. NIIT: the 3.8% net investment income tax applies to the taxable (post-exclusion) part of the gain once modified adjusted gross income exceeds $200,000 single or $250,000 joint, and the gain itself counts toward that threshold. To see which federal bracket a taxable gain tops out in, run it through the tax bracket calculator.

Run your own numbers

See where a taxable gain lands on top of your income.

Any gain above the exclusion stacks onto your other income for the year, which decides whether it is taxed at 0%, 15%, or 20% and whether the 3.8% NIIT bites. Run your income plus the taxable slice through the federal income tax calculator before you set a closing date.

Model my sale year
FAQ

Home Sale Capital Gains, answered.

The questions people actually ask about this topic, in plain language.

Written for borrowers, not bankersPlain-language, jargon-freeReviewed quarterly
Do I have to pay capital gains tax if I buy another house with the money?

Buying another house changes nothing. The old rollover rule that deferred gain when you bought a replacement home was repealed in 1997 and replaced by the Section 121 exclusion, which does not care what you do with the proceeds. Your tax depends only on the size of the gain, your exclusion ($250,000 single, $500,000 married filing jointly), and your basis records.

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

Two years. You must have owned the home and used it as your main residence for at least 24 months out of the 5 years ending on the sale date, and the months do not need to be continuous. Sell earlier because of a qualifying job move (50+ miles), health reasons, or unforeseen circumstances and you get a pro-rated share of the exclusion: 12 months of residence earns half of it.

Do I pay tax on the full sale price or just the gain?

Only the gain, and only the part above your exclusion. The gain is the sale price minus selling costs (agent commission, seller-paid closing costs) minus your adjusted basis: what you originally paid plus documented capital improvements and certain purchase closing costs. Selling a $900,000 house never means tax on $900,000; a couple who bought it for $350,000 is taxed on at most $550,000 of gain, and the $500,000 exclusion typically shrinks that to $50,000.

What if I inherited the house?

Inherited homes get a stepped-up basis: your cost basis resets to the home's fair market value on the date of the previous owner's death, so all the appreciation during their lifetime is never taxed. Sell soon after inheriting and there is usually little or no gain at all, which makes the Section 121 exclusion mostly irrelevant. If you keep the home and live in it as your main residence for 2 years, you can also qualify for the exclusion on any growth after the step-up.

Can I avoid capital gains on a rental property by moving into it?

Only partly. Living in a former rental for 2 years does qualify you for the exclusion, but under the post-2008 nonqualified use rule the gain is split by time: the share of your ownership years the home spent as a rental (after 2008, before you moved in) can never be excluded. Rent a home for 6 years, live in it 2, and only 2/8 of the gain is even eligible. Depreciation claimed during the rental years is also recaptured at up to 25% regardless.

Is there still a one-time capital gains exemption for people over 55?

No. The one-time $125,000 over-55 exclusion was repealed in 1997. It was replaced by the current Section 121 exclusion, which is better on every axis: larger ($250,000 single, $500,000 married filing jointly), available at any age, and reusable once every 2 years as long as you meet the ownership and use tests each time.

Do I have to report my home sale to the IRS if I owe no tax?

Not always. If your entire gain is covered by the exclusion and the closing agent did not issue a Form 1099-S, the sale does not appear on your return at all. If you did receive a 1099-S, report the sale on Form 8949 and Schedule D even though the excluded gain produces no tax, so the IRS can match the form. You can usually avoid the 1099-S by certifying at closing that you qualify for the full exclusion.

How much tax will I pay on the gain above the exclusion?

The taxable slice is a long-term capital gain (assuming you owned the home more than a year) taxed at 0%, 15%, or 20% depending on your total taxable income. In 2026 the 15% rate covers taxable income up to $533,400 single or $600,050 married filing jointly, so most sellers pay 15% on the excess. Add the 3.8% net investment income tax if the gain pushes your modified adjusted gross income over $200,000 single or $250,000 joint, plus state income tax in most states.