The primary residence exemption eliminates capital gains tax for most homeowners
If you lived in the home as your main residence for at least two of the last five years before selling, you do not owe federal capital gains tax on the profit — up to $250,000 if you are single, or $500,000 if you are married filing jointly. This is not a loophole or a special program you apply for. It is a permanent rule in the tax code. The IRS does not require you to claim it separately; you simply report the sale on your tax return and exclude the gain if you meet the residency test.
The exemption covers the difference between what you paid for the home (your basis) and what you sold it for (the sale price), minus certain improvements you made. If you bought for $200,000, made $50,000 in capital improvements, and sold for $400,000, your gain is $150,000. That entire amount is tax-free if you meet the two-year rule. You owe nothing to the IRS.
Key Takeaways
- The primary residence exemption erases federal capital gains tax on up to $250,000 (single) or $500,000 (married) of home sale profit if you lived there two of the last five years.
- Capital improvements like a new roof, kitchen remodel, or addition increase your basis and reduce your taxable gain, but cosmetic repairs and maintenance do not count.
- If you sell within two years of buying, or if you did not live there full-time, you may owe tax on part or all of the gain, though exceptions exist for job changes and health emergencies.
- State and local taxes on home sales vary widely; some states have no capital gains tax, while others tax the full gain regardless of the federal exemption.
- You report the sale on Form 8949 and Schedule D, and the IRS does not pre-approve the exemption — you claim it when you file your return.
How the two-year residency test works
You must have owned the home and lived in it as your primary residence for at least two of the five years immediately before the sale. The two years do not have to be consecutive, and you do not have to be living there on the day you sell. If you bought a house in January 2020, lived there until June 2022, moved out, and sold it in March 2024, you meet the test: you owned it for over four years and lived there for more than two years within the five-year window.
The IRS measures this by counting days. If you lived there 730 days or more out of the 1,825 days in the five-year lookback period, you may have access to. Temporary absences — a job assignment out of state, a medical stay, a sabbatical — usually count as time you lived there, as long as you maintained the home as your residence and returned to it.
If you do not meet the two-year test, you cannot use the exemption. You will owe federal capital gains tax on the full profit at either the long-term rate (15% or 20% for most people) or the short-term rate (your ordinary income tax bracket) depending on how long you owned it. Some states allow a partial exemption if you lived there one year instead of two, but federal law does not.
Capital improvements that reduce your taxable gain
Your taxable gain is the sale price minus your basis. Your basis starts as the price you paid, but it increases when you make capital improvements — permanent upgrades that add value or extend the life of the home. A new roof, a kitchen remodel, an addition, new windows, a deck, or a furnace replacement all count. You add the cost of these improvements to your basis, which lowers your gain and your tax bill.
Repairs and maintenance do not count. Painting, fixing a leak, replacing a broken window, or routine upkeep are not capital improvements. The difference is whether the work adds value or simply restores the home to its original condition. If you repaint the entire exterior and that adds $15,000 to the home's value, it is still a repair, not an improvement, because paint is maintenance. If you replace the siding with new material that lasts 30 years, that is an improvement.
Keep receipts and invoices for any major work. When you sell, you will need to document the cost of improvements to support your basis calculation. The IRS does not require you to submit these with your return, but you must have them if you are audited. If you cannot prove the cost, you cannot deduct it from your gain.
Exceptions to the two-year rule for job changes and health crises
If you sell before living there two years, you may still claim a partial exemption if you sold because of a change in employment, a health condition, or an unforeseen circumstance. The IRS defines these narrowly. A job transfer to a different city, a diagnosis that requires you to move closer to medical care, or a death in the family that forces a sale can may have access to. A job loss, a divorce, or a desire to move do not.
The partial exemption is calculated as a fraction: the number of months you lived there divided by 24, times the full exemption amount. If you lived there 12 months and sold due to a job change, you can exclude half of your gain (up to $125,000 if single). You still need to document the reason for the sale — a job offer letter, a medical record, or a death certificate — and report it on Form 8949.
If you do not may have access to for the partial exemption, you owe tax on the entire gain. There is no other federal workaround. Some states offer their own partial exemptions, but you must check your state's rules separately.
State and local capital gains taxes on home sales
The federal exemption does not shield you from state or local capital gains tax. Most states do not tax capital gains at all, but a growing number do. California, New York, Illinois, and Washington all tax long-term capital gains on home sales. Some states tax the full gain; others offer their own primary residence exemption similar to the federal rule.
California, for example, taxes capital gains as ordinary income with no exemption for primary residences. If you sell a home in California and your gain is $300,000, you owe California state income tax on the full amount at your marginal rate, even though the federal exemption shields you. New York offers a partial exemption for primary residences but not the full $250,000 or $500,000 that the federal rule provides.
Check your state's tax authority website or speak with a tax professional before you sell. The state tax can be substantial and is separate from the federal calculation. Some counties also impose local transfer taxes or gains taxes, which are additional.
How to report the sale and claim the exemption on your tax return
You report the home sale on Form 8949 (Sales of Capital Assets) and Schedule D (Capital Gains and Losses). Form 8949 asks for the date you bought the home, the date you sold it, the sale price, your basis, and the gain or loss. Schedule D summarizes your long-term and short-term gains and losses for the year.
On Form 8949, you will see a box for "Code" — this is where you indicate the reason for the sale. If you lived there two of the last five years and are claiming the primary residence exemption, you enter code "D" and the amount of the exemption. The IRS will subtract that amount from your gain, and the remainder (if any) is taxable.
You do not need to submit proof of residency or capital improvements with your return. The IRS does not pre-approve the exemption. You claim it based on your own records, and if you are audited, you must produce documentation: a mortgage statement or deed showing you owned it, utility bills or a lease showing you lived there, receipts for improvements, and the settlement statement from the sale showing the sale price.
If you are unsure whether you meet the two-year test or whether your improvements count, a tax professional can review your situation before you file. The cost of a consultation is usually far less than the tax bill if you claim the exemption incorrectly.
What happens if you sell a second home or investment property
The primary residence exemption applies only to homes you lived in as your main residence. If you own a vacation home, a rental property, or a home you bought as an investment, you cannot use the exemption. You will owe capital gains tax on the full gain at the long-term rate (15% or 20%) if you held it more than one year, or at your ordinary income tax rate if you held it one year or less.
If you own multiple homes and sell more than one in the same year, you can use the exemption for only one — the one that was your primary residence. If you owned a home as your primary residence, moved out, rented it to tenants, and then sold it, you may lose part or all of the exemption depending on how long you rented it. The IRS looks at the use of the home in the two years before the sale; if you rented it for the entire two years, you do not may have access to.
If you converted a rental property back to your primary residence before selling, you may be able to claim a partial exemption for the years you lived there, but the calculation is complex and depends on when you converted it. A tax professional should review this situation.
Frequently Asked Questions
Do I have to live in the home for two full years before I can sell without paying capital gains tax?
No. You need to have lived there for at least two of the five years before the sale, and those years do not have to be consecutive. You could live there for one year, move out for two years, move back for one year, and then sell — you would still may have access to because you lived there two years within the five-year window.
What if my spouse and I own the home together but only one of us lived there?
Both spouses must meet the two-year residency test to claim the full $500,000 exemption. If only one spouse lived there, you can claim only the $250,000 single exemption. If neither spouse lived there, you cannot claim the exemption at all.
Can I use the exemption more than once?
You can use it once every two years. If you sold a home in 2022 and claimed the exemption, you cannot claim it again until 2024. If you sell a second home in 2023, you will owe tax on that gain. This rule prevents people from flipping homes and avoiding tax repeatedly.
What if I inherited the home from a parent — does that change my basis?
Yes. When you inherit a home, your basis is stepped up to the fair market value on the date of death, not what your parent paid for it. If your parent bought the home for $100,000 and it was worth $400,000 when they died, your basis is $400,000. If you sell it for $420,000, your gain is only $20,000. You still need to meet the two-year residency test to use the exemption, but the step-up in basis usually eliminates most or all of the gain.
Do I owe capital gains tax if I sell at a loss?
No. If you sell for less than your basis, you have a loss, not a gain. You cannot deduct a loss on a primary residence from your other income. The loss simply disappears for tax purposes. You report it on Schedule D, but it does not reduce your tax bill.