When you sell a home for more than you paid, the profit is a capital gain. For most homeowners who sell a primary residence, the federal tax code provides an exclusion large enough to cover the entire gain - and they owe nothing to the IRS. But the exclusion has rules, the rules have exceptions, and failing to meet them can produce a tax bill that surprises sellers who assumed they would owe nothing.
The rules come from Section 121 of the Internal Revenue Code. IRS Publication 523, "Selling Your Home," is the authoritative reference for every situation described below.
What capital gains tax applies to home sales
A capital gain is the difference between what you received for the property and what you paid, adjusted for costs. The formula is: sale price minus selling expenses (agent commissions, title fees, and other costs of sale) minus your adjusted cost basis (original purchase price plus capital improvements).
The resulting figure - your taxable gain - is then subject to federal capital gains tax. Short-term gains (on property held one year or less) are taxed as ordinary income at your marginal rate, which can be as high as 37 percent. Long-term gains (property held more than one year) are taxed at preferential rates: 0, 15, or 20 percent depending on your income, as established by federal tax law and confirmed in current IRS rate schedules. Most homeowners who have lived in their home for several years will have long-term gains.
State income tax may also apply. Many states follow federal capital gains treatment, but some tax capital gains as ordinary income, and a handful have no income tax at all. The analysis below covers federal tax only.
The primary residence exclusion: $250,000 single, $500,000 married
Section 121 allows homeowners who meet the ownership and use tests to exclude from gross income up to $250,000 of gain on the sale of a primary residence ($500,000 for a married couple filing jointly). This exclusion is one of the most valuable provisions in the federal tax code for individual taxpayers.
The exclusion is not a one-time benefit. You can use it repeatedly, as long as you meet the two-year tests and have not claimed the exclusion on a different home sale within the prior two years.
Example: A married couple bought their home in 2016 for $320,000 and sells it in 2026 for $720,000. After $24,000 in selling costs and $40,000 in capital improvements added to the basis, their adjusted basis is $360,000. Their gain is $720,000 minus $360,000, which equals $360,000. The $500,000 married exclusion covers the entire $360,000 gain, and they owe no federal capital gains tax.
Example: A single taxpayer bought a home in 2019 for $300,000 and sells for $600,000. After $18,000 in selling costs and $20,000 in improvements, the adjusted basis is $338,000. The gain is $262,000. The $250,000 exclusion covers most but not all - $12,000 is taxable as a long-term capital gain. At a 15 percent rate, that is $1,800 in federal tax.
The two-year ownership and use test: how to qualify
The exclusion requires meeting two separate tests:
Ownership test: You must have owned the home for at least 24 of the 60 months immediately before the sale date.
Use test: You must have used the home as your primary residence for at least 24 of the 60 months immediately before the sale date.
The 60-month window means you can count any period of ownership and primary residence use in the five years before the sale. The two years do not have to be continuous. A homeowner who lived in the home for two years, rented it for one year, moved back for six months, and then sold it can still qualify if total qualifying use adds up to 24 months within the five-year window.
You cannot use the exclusion if you excluded gain on another home sale within the two years ending on the sale date of the current property.
What counts as your cost basis and how improvements reduce your gain
Your cost basis starts with what you paid for the property: the purchase price plus certain acquisition costs, including closing costs such as attorney fees, recording fees, and title insurance. Points paid on your original mortgage may also be added depending on how they were treated for tax purposes.
Capital improvements increase your basis. IRS Publication 523 defines a capital improvement as work that adds value, prolongs the useful life of the home, or adapts it to a new use. Examples include:
- Adding a room, deck, or garage
- A new roof
- Central air conditioning or HVAC system installation
- Kitchen or bathroom remodel that adds lasting value
- New windows and exterior doors
- Landscaping that qualifies as a permanent improvement
Routine repairs and maintenance do not increase your basis. Painting interior walls, replacing a broken faucet, fixing a leaky gutter, or patching driveway cracks are repairs - necessary but not capital improvements. The distinction matters most when your gain approaches or exceeds the exclusion threshold.
Keep all improvement receipts for as long as you own the property and for three years after you file the tax return for the year of sale. If you sell and claim the exclusion for a gain that exactly fits under the limit because of improvements, having documentation protects you if the IRS reviews your return.
Partial exclusions: what happens if you sell before two years
If you do not meet the full two-year ownership and use tests, you may still qualify for a partial exclusion if the sale was primarily caused by a change in employment, a change in health, or unforeseen circumstances, as specified under IRS regulations.
Qualifying unforeseen circumstances include multiple births from the same pregnancy, death of a co-owner, divorce, or certain job losses. Natural disasters affecting the property may also qualify.
The partial exclusion is calculated as a fraction: the number of qualifying months divided by 24 (or by the number of months in the applicable window), multiplied by the maximum exclusion amount. A single taxpayer who owned and used the home for 12 months and qualifies for an unforeseen-circumstances partial exclusion would be eligible for 12/24 times $250,000, or $125,000 of the exclusion.
If you do not qualify even for a partial exclusion - you sell before two years for reasons that do not meet the IRS categories - the entire gain is taxable.
Investment properties and second homes: different rules apply
Section 121 applies only to a home you used as your primary residence. Investment properties - homes held for rental income or appreciation - and second homes (vacation or seasonal use) do not qualify for the $250,000 or $500,000 exclusion.
When you sell an investment property, the entire gain is taxable. The applicable tax rate depends on how long you held the property and your income level. In addition, depreciation deductions you took while the property was a rental reduce your cost basis and create additional taxable gain when you sell - this is called depreciation recapture, and it is taxed at a maximum federal rate of 25 percent, regardless of how long you held the property.
Second homes face similar treatment. A home used exclusively for personal use but not as your primary residence - a beach house, a mountain cabin - does not qualify for the primary residence exclusion.
Some homeowners convert a rental property to a primary residence before selling, attempting to qualify for the exclusion. IRS rules account for this. Under the Housing Assistance Tax Act rules, gains attributable to non-qualified use (periods when the property was not a primary residence after 2008) are not eligible for the exclusion. A complex calculation applies.
If your situation involves a rental-to-primary conversion, an inherited property, or a sale with a gain above the exclusion limit, consult a licensed tax professional. The cost of professional advice is small compared to the tax exposure.
How to report a home sale on your federal tax return
The sale of a primary residence that qualifies entirely for the Section 121 exclusion typically does not need to be reported on your federal return if the gain is entirely excluded. However, you must report the sale if:
- You received a Form 1099-S from the closing agent
- Part of the gain exceeds the exclusion limit
- You used any portion of the home for business or rental purposes
- You choose to report the sale for documentation purposes
Form 8949 and Schedule D are the federal forms used to report capital gains from real estate. If any gain is taxable after applying the exclusion, it flows from Form 8949 to Schedule D and then to Form 1040.
Your closing agent is required to file a Form 1099-S with the IRS if the sale price exceeds certain thresholds - generally $250,000 for a primary residence, though this can vary. If you receive a 1099-S, the IRS has a record of the sale and expects either a matching return entry or an explanation.
For context on how capital gains treatment differs when you rent a property instead of selling it, and the carrying-cost math behind that decision, see Realtor vs. For Sale By Owner: A Comparison for how selling costs affect the net proceeds you start your gain calculation from.
See How Much Does It Cost to Sell a House? for a complete breakdown of seller costs including commissions, transfer taxes, and closing fees that reduce your net proceeds - and your taxable gain.
Frequently asked questions
Do I have to pay taxes if I sell my house for a profit?
Most homeowners who sell a primary residence owe no capital gains tax because the $250,000 single or $500,000 married filing jointly exclusion exceeds their gain. The exclusion requires meeting two-year ownership and use tests. Gains above the exclusion are taxable. Investment properties and second homes do not qualify for this exclusion and are taxed differently.
How long do I have to live in a house to avoid capital gains?
The primary residence exclusion requires that you owned the home and used it as your primary residence for at least 24 months out of the 60 months preceding the sale, according to IRS Publication 523. The two years do not have to be consecutive. You must also not have claimed the exclusion on another home sale within the past two years.
Can I deduct home improvement costs from my capital gains?
Yes. Capital improvements increase your cost basis, which reduces your taxable gain. Qualifying improvements include additions, new systems (roof, HVAC, kitchen remodel), and structural work. Routine maintenance and repairs do not qualify. Keep all receipts for improvements made during ownership - the IRS can ask for documentation if your gain approaches or exceeds the exclusion threshold.
What happens if my gain exceeds the $500,000 exclusion?
The gain above the exclusion limit is taxable as a long-term capital gain if you owned the home for more than one year. Long-term capital gains tax rates are 0, 15, or 20 percent depending on your income, according to IRS guidance. A gain of $600,000 for a married couple filing jointly would result in $100,000 of taxable gain. Consult a tax professional for your specific situation.
Do I owe capital gains if I inherited the house?
Inherited property receives a stepped-up cost basis equal to the fair market value at the date of the original owner's death. This means if you inherit a home worth $400,000 and sell it for $410,000 shortly after, you owe capital gains only on the $10,000 difference, not on decades of prior appreciation. The primary residence exclusion does not apply to an inherited property you did not live in.
Does a 1031 exchange apply to a primary residence?
No. A Section 1031 like-kind exchange defers capital gains on the sale of investment property when you reinvest proceeds into another investment property. It does not apply to a primary residence. Primary residences use the Section 121 exclusion instead. If you convert a rental property to a primary residence or vice versa, the rules become more complex and a tax professional should review your situation.