Selling Your Home and Capital Gains: How the Home Sale Tax Exclusion Works
What You’ll Learn
- How gain is calculated from your amount realized and adjusted basis
- Which projects generally count as improvements, and which are repairs
- The ownership, use and lookback tests for the home sale exclusion
- When a partial exclusion may apply
- How home office, rental and second-home use complicate the math
- Form 1099-S, state taxes and why your records matter
Home sale capital gains are one of the most misunderstood parts of selling a house. Many sellers owe no federal income tax on the gain from selling their main home, but the exclusion isn't automatic. It depends on how your gain is calculated, how long you owned and lived in the home, and how the home was used. Knowing the basics before you list helps you estimate what you'll actually keep and spot situations worth a conversation with a tax professional. This article covers federal rules in general terms; tax law can change, and state rules vary.
How your gain is calculated
Your gain isn't simply the sale price minus what you paid. The IRS formula is:
Gain = amount realized minus adjusted basis
- Amount realized is generally the sale price minus your selling costs, such as real estate commissions, title and legal fees, and other closing costs you pay as the seller. See seller closing costs for what those can include.
- Adjusted basis generally starts with what you paid for the home, plus certain purchase costs from your closing (such as some title and recording fees), plus the cost of capital improvements. It's reduced by certain items, such as any depreciation you claimed.
Gain is not the same as the cash you walk away with. Paying off your mortgage doesn't change your gain, and a large loan balance doesn't reduce it.

Improvements vs. repairs
This distinction can matter a lot, because capital improvements generally add to your basis and routine repairs generally don't.
- Improvements add value, extend the home's life or adapt it to new uses. Examples: a new roof, an addition, a replaced HVAC system, a remodeled kitchen, a new deck, a fence, or new windows.
- Repairs keep the home in ordinary working condition. Examples: fixing a leak, patching drywall, repainting a room, or replacing a broken pane of glass.
Repair-type work done as part of a larger remodeling project may count as part of that improvement. Improvements that have since been removed or replaced generally no longer count. When in doubt, keep the receipt and ask a tax professional. For a different angle on projects, see what actually adds value before you list.

A worked example (hypothetical)
Example (hypothetical round numbers, for illustration only):
- Purchase price: $200,000, plus $10,000 in qualifying purchase costs and $50,000 in capital improvements, for an adjusted basis of $260,000.
- Sale price: $600,000, minus $40,000 in selling costs, for an amount realized of $560,000.
- Gain: $560,000 minus $260,000 equals $300,000.
If a single filer meets the tests below, up to $250,000 of that gain could be excluded, leaving $50,000 potentially taxable. A married couple filing jointly who meets the tests could potentially exclude the full amount. Notice that if the improvements couldn't be documented and counted, the gain would be $50,000 higher. Your actual numbers and tax result depend on your situation.
The exclusion: limits and tests
Under federal law (Internal Revenue Code Section 121), you may be able to exclude up to $250,000 of gain from the sale of your main home, or up to $500,000 for most married couples filing jointly, if you meet these tests:
- Ownership test: you generally owned the home for at least 2 of the 5 years before the sale.
- Use test: you generally lived in it as your main home for at least 2 of those 5 years. The two years don't have to be consecutive, and they don't have to be the same two years as the ownership test.
- Lookback test: you generally can't have used the exclusion on another home sale in the 2 years before this one.
For the higher joint limit, generally at least one spouse must meet the ownership test, both must meet the use test, and neither can have used the exclusion in the prior 2 years. Your main home is generally where you live most of the time; you can only have one at a time. Certain members of the uniformed services and Foreign Service and some others may be able to suspend part of the 5-year period. IRS Publication 523, Selling Your Home lays out the full rules and worksheets.
These limits haven't changed since 1997. Congress has considered proposals to change these limits; confirm current law with a tax professional.

If you don't meet the full tests: partial exclusion
If you sell before meeting the 2-year tests, you may still qualify for a partial exclusion if the main reason for the sale was a change in place of employment, health, or certain unforeseen circumstances as the IRS defines them. The partial amount is generally based on how much of the 2-year period you did meet. The rules for what qualifies are specific, so review them with a tax professional before you assume either way.
Situations that complicate the math
- Home office or rental use. If you claimed depreciation for a home office or for renting out part or all of the home after May 6, 1997, that depreciation generally can't be excluded and may be taxed when you sell.
- A former rental or second home. The exclusion applies to your main home. If the home was a rental or second home before it became your main home, part of the gain may not qualify even if you later meet the 2-of-5-year tests. Gain on a vacation home you never lived in as your main home generally doesn't qualify. See selling a vacation home and selling a rental with tenants in place.
- Divorce, separation or the death of a spouse. Special rules can affect how ownership and use time is counted and which limit applies. If any of these apply, ask a tax professional how the rules fit your situation.
- Inherited or gifted homes have their own basis rules, which differ from a home you bought.

Reporting the sale and Form 1099-S
The closing or settlement agent may be required to file Form 1099-S, which reports the sale proceeds to the IRS. In some cases it isn't required, for example when the seller provides certain written certifications that the gain is fully excludable. If you receive a Form 1099-S, you generally must report the sale on your tax return, even if your gain is fully excluded. If your gain is more than the exclusion, or you don't qualify, the taxable portion is reported as a capital gain. A tax professional can make sure it's reported correctly.
State income tax may also apply
Federal rules are only part of the picture. Many states tax capital gains as income, some follow the federal exclusion and some have no income tax at all. Some states also require withholding at closing when the seller lives out of state. Ask a tax professional or your closing agent what applies where the home is located.
Why your records matter
Your records are how you prove your basis. Without them, you may not be able to count improvements you paid for, which can mean a larger taxable gain. Keep:
- The closing statement from when you bought the home
- Receipts, invoices and contracts for capital improvements, plus related permits
- Records of any depreciation claimed for a home office or rental use
- The closing statement from your sale
According to IRS guidance on how long to keep records, records supporting your home's basis should be kept for as long as you own the home and until the period of limitations expires for the year you sell, generally 3 years after you file that return.

Before you list
- Estimate your gain: rough sale price, minus selling costs, minus your adjusted basis.
- Check your dates against the 2-of-5-year ownership and use tests and the 2-year lookback.
- Gather your records now, while receipts are easier to find.
- Talk with a tax professional before you set a listing date. If you're close to meeting a test, timing can matter.
Frequently asked questions
Do I have to pay capital gains tax when I sell my house?
Not necessarily. If you meet the ownership and use tests, you may be able to exclude up to $250,000 of gain, or $500,000 for most married couples filing jointly. Gain above that, or gain that doesn't qualify, may be taxable. State tax may also apply.
What if I haven't lived in the home for 2 years?
You may qualify for a partial exclusion if the main reason for selling was a work change, health or certain unforeseen circumstances. Otherwise, the gain may be taxable. Ask a tax professional before you list.
Do home improvements reduce capital gains?
Capital improvements, like a new roof or an addition, generally add to your basis, which reduces your gain. Routine repairs generally don't. Keep the receipts.
Will I receive a Form 1099-S?
Possibly. The closing agent may be required to file one. If you receive it, you generally must report the sale on your return, even if the gain is fully excluded.
This article is general information, not tax or legal advice. Federal and state tax laws can change, and how they apply depends on your situation. The example uses hypothetical numbers for illustration only. Consult a tax professional about your sale.
