The short answer
Under section 121 of the Internal Revenue Code, you leave out up to $250,000 of the gain on selling your main home, or up to $500,000 on a joint return, if you owned it and lived in it as your main home for at least 2 years in the 5 years before the sale. The two years need not be in a row. You can use the exclusion once every 2 years.
| Your situation | Most gain you can exclude |
|---|---|
| Single, head of household, or married filing separately, meeting the tests | $250,000 |
| Married filing jointly, both spouses meeting the use test, one meeting the ownership test, and neither having used the exclusion in the last 2 years | $500,000 |
| Unmarried surviving spouse selling within 2 years of the death, not remarried, if the tests were met just before the death | $500,000 |
| Tests not met, but the sale was for work, health or an unforeseen event | A part of the limit, by the months you met the tests |
These amounts are written into the statute and are not raised for inflation. The methodology page gives the sources.
How the gain is worked out
The gain is what you receive less what you paid. Start with the sale price and take off the selling costs (agent commissions, title and legal fees). Then take your basis: the purchase price, closing costs you added to it, and the cost of improvements, less any depreciation you claimed or could have claimed. The difference is the gain. A loss on the sale of a main home is not deductible.
Worked example. A single filer sells for $850,000 and pays $50,000 in selling costs, so the amount realized is $800,000. They paid $350,000 and put in $40,000 of improvements, so the basis is $390,000 and the gain is $410,000. The exclusion covers $250,000, leaving $160,000 taxable. With $120,000 of other income in 2027, the federal tax on that is $24,000 and the 3.8% net investment income tax adds $3,040, a total of $27,040. The same function that runs the calculator worked this out, and its tests check the method by hand against the IRS worksheets.
Capital gains tax on the sale of a home
The gain left after the exclusion is a capital gain. If you owned the home for more than a year it is a long-term gain, taxed at 0%, 15% or 20% depending on your total taxable income. For 2027 a single filer pays 0% up to $51,050 of taxable income and 15% up to $563,200; above that the rate is 20%. A home owned a year or less is taxed as ordinary income. The gain is added on top of your other income, so a large sale can push part of it into a higher rate than you normally pay.
Net investment income tax. The taxable part of a home sale also counts as net investment income. If your modified adjusted gross income is over $200,000 ($250,000 on a joint return), you owe 3.8% on the smaller of your net investment income (the gain and any other investment income) and the income over that line. The calculator shows this separately, and the amount the sale adds on top of what your other investment income already owes. For the rules on other investment sales, see the capital gains calculator.
If you do not meet the two-year tests
A shorter stay can still give a partial exclusion when the main reason for the sale was a change of workplace, a health issue or an unforeseen event. The limit is cut in proportion: the shortest of the time you lived there, the time you owned it, and the time since you last used the exclusion, divided by 24 months, times the full limit.
Example. A single filer moves for a new job after 12 months in a home that cost $200,000 and sells it for $500,000. The gain is $300,000. The limit is $125,000 (12 of 24 months), so $175,000 is taxable.
Rental use, a home office and depreciation
Two rules take some gain out of the exclusion. First, gain up to the depreciation you claimed or could have claimed on the home after 6 May 1997 cannot be excluded. It is taxed at your ordinary rate up to a maximum of 25% (“unrecaptured section 1250 gain”). Second, gain that belongs to a period after 2008 when the home was not your main home (a rental or a vacation home, including a rental between two periods of living there; temporary absences for work, health or unforeseen reasons, up to 2 years in total, and qualified official extended duty, up to 10 years, are exceptions) cannot be excluded either, in proportion to that time. Time after you moved out for good does not count against you, but only the part inside the 5 years before the sale.
IRS Publication 523's own example: a home bought for $400,000, rented for 2 years (with $20,000 of depreciation), lived in for 2 years, moved out a year before the sale, and sold for $700,000 has a gain of $320,000. The depreciation part ($20,000) is not excludable. Two of the five years were rental use, so two fifths of the remaining gain ($120,000) is not excludable either. That leaves $180,000 excluded and $140,000 taxable, of which $20,000 is the depreciation taxed up to 25%. If you sell a rental property that was never your home, or want to defer the gain, see depreciation recapture and 1031 exchanges on the capital gains calculator.
What this calculator leaves out
- It is the federal tax. A state may tax the gain, with its own rules for the exclusion.
- It does not split a home used partly for business. A separate business or rental part is a sale reported on Form 4797.
- A home you acquired in a like-kind (section 1031) exchange cannot use the exclusion for 5 years after the exchange.
- It does not cover the extended periods for military, Foreign Service and intelligence community members, a home destroyed or condemned, the rules after a divorce, or someone subject to the expatriate tax.
- It assumes you use the standard deduction and have no other capital gains, losses or qualified dividends this year.
Frequently asked questions
How much of the gain on selling a home is tax-free?
Up to $250,000 for a single filer, or $500,000 for a married couple filing jointly, when you owned the home and lived in it as your main home for at least 2 of the 5 years before the sale and have not used the exclusion on another home in the last 2 years.
Do the two years have to be in a row?
No. You need 24 months of ownership and 24 months of use as your main home in the 60 months before the sale. They can be separate periods and need not be the same months.
Is there capital gains tax if I sell my house for a profit?
Only on the gain above the exclusion. Gain up to your limit is not taxed. The rest is a capital gain, taxed at 0%, 15% or 20% if you owned the home more than a year, plus the 3.8% net investment income tax if your income is over its line.
What if I lived in the home less than two years?
If you sold because of a change of workplace, a health issue or an unforeseen event, you may qualify for a partial exclusion in proportion to the months you met the tests. If not, the gain is taxable, and is a short-term gain taxed as ordinary income if you owned the home a year or less.
Does depreciation from a home office or rental reduce the exclusion?
Yes. Gain up to the depreciation allowed or allowable after 6 May 1997 cannot be excluded, and is taxed at your ordinary rate up to a 25% maximum.
Can I use the exclusion on a home I bought with a 1031 exchange?
Not for 5 years after the exchange. A home acquired in a like-kind exchange cannot use the section 121 exclusion if it is sold within 5 years of the date it was acquired.