How to Avoid Capital Gains Tax on Real Estate: 7 Ways
Tax Planning
How to avoid capital gains tax on real estate: 7 ways
The tax on a property sale depends on what kind of property it is. A main home can qualify for a large exclusion. A rental cannot, but its tax can be deferred or spread out.

To avoid capital gains tax on real estate, start with the home sale exclusion: if you owned and lived in your main home for at least two of the five years before the sale, you can exclude up to $250,000 of gain, or $500,000 on a joint return. Beyond that, you can shrink the gain by adding improvements and selling costs to your basis, hold the property more than a year for long-term rates, defer tax on investment property with a 1031 like-kind exchange, spread the gain with an installment sale, and offset it with capital losses. Rentals also face tax on past depreciation at up to 25%.
If you want to know how to avoid capital gains tax on real estate, the first question is which kind of property you are selling. The tax code treats a main home, a rental and a vacation house very differently, and a strategy that works for one is not allowed for another.
This post goes through seven legal ways to reduce the tax, shows which ones fit which property, and works two examples with round numbers. For the rates and income thresholds, see our hub post on capital gains tax rates for 2026 and 2027.
How capital gains tax on real estate works
Your gain is the amount you realize from the sale minus your adjusted basis. IRS Publication 523, Selling Your Home, lays it out in two lines: selling price minus selling expenses equals the amount realized, and amount realized minus adjusted basis equals your gain or loss. Basis starts with what you paid and goes up with improvements.
How the gain is taxed depends on four things, all from IRS Topic 409, Capital gains and losses, and Topic 559, Net investment income tax:
- Holding period. Hold the property more than one year and the gain is long-term, taxed at 0%, 15% or 20% depending on your taxable income. One year or less and it is short-term, taxed as ordinary income.
- Depreciation. If you claimed depreciation on a rental, that part of the gain (called unrecaptured section 1250 gain) is taxed at a maximum 25% rate.
- Net investment income tax. A 3.8% tax can apply when your modified adjusted gross income is above $200,000 if single or head of household, $250,000 if married filing jointly, or $125,000 if married filing separately.
- Personal losses. A loss on the sale of your own home is not deductible.
Which strategies fit which property
| Strategy | Main home | Rental or investment property | Vacation home you do not rent |
|---|---|---|---|
| Home sale exclusion | Yes | No, unless it was your main home for two of the last five years | No |
| Add improvements and selling costs to basis | Yes | Yes | Yes |
| Hold more than one year | Yes | Yes | Yes |
| 1031 like-kind exchange | No | Yes | No |
| Installment sale | Yes | Yes | Yes |
| Offset with capital losses | Yes | Yes | Yes |
1. Use the home sale exclusion
This is the largest break available to most households. IRS Topic 701, Sale of your home, says you may exclude up to $250,000 of gain from your income, or up to $500,000 if you file a joint return with your spouse.
To qualify you must meet two tests during the five-year period ending on the date of sale:
- Ownership. You owned the home for at least 24 months.
- Use. You lived in it as your main home for at least 24 months.
Publication 523 adds that the 24 months do not have to be one continuous block, and that you may take the exclusion only once in a two-year period. For the $500,000 amount on a joint return, only one spouse has to meet the ownership test, but each spouse must meet the residence requirement and neither can have used the exclusion in the prior two years.
A surviving spouse can still use the $500,000 amount if the sale happens within two years of the spouse’s death, the survivor has not remarried, and the other conditions were met. Members of the uniformed services, the Foreign Service and the intelligence community on qualified extended duty can suspend the five-year test period for up to 10 years.
Gain you exclude also escapes the 3.8% net investment income tax. Topic 559 says that tax does not apply to the portion of a home sale gain that is excluded for income tax purposes.
2. Claim a partial exclusion if you had to move early
If you sell before reaching 24 months, you may still get part of the exclusion. Publication 523 allows it when the main reason for the sale is a work-related move (a new job at least 50 miles farther from the home), a health-related move, or an unforeseeable event such as a casualty, death, divorce or unemployment.
The partial amount is prorated. Take the shortest of the time you lived in the home, the time you owned it, or the time since you last used the exclusion. Divide by 24 months and multiply by $250,000. A single owner who lived in a home for 12 months before a qualifying job move could exclude up to 12 divided by 24, times $250,000, or $125,000.
3. Raise your basis with improvements and selling costs
Every dollar added to basis is a dollar less of gain. Publication 523 lists improvements that count, including:
- Additions: a bedroom, bathroom, deck, garage, porch or patio
- Systems: heating, central air, wiring, a security system
- Exterior: a new roof, new siding, storm windows, insulation
- Grounds: landscaping, a driveway, a fence, a swimming pool
- Interior: kitchen modernization, flooring, built-in appliances
Repairs and maintenance that keep the home in good condition do not count. Painting, fixing leaks and replacing broken hardware are repairs. The publication’s own example draws the line: replacing a broken windowpane is a repair, and replacing all the windows is an improvement.
Selling expenses reduce the amount you realize, and certain settlement costs from your purchase, such as legal fees, recording fees, transfer taxes and owner’s title insurance, can be added to basis. Keep the receipts. People who have owned a home for 25 years often leave tens of thousands of dollars of improvements off the calculation because the paperwork is gone.
4. Hold for more than a year and choose the year of sale
Selling one day after the one-year mark instead of one day before moves the gain from ordinary income rates to the 0%, 15% or 20% long-term rates. For a flip or an inherited-then-renovated property, the calendar alone can change the bill.
The year matters too. Long-term rates are tied to your taxable income, so the same gain costs less in a year when your other income is low, such as the first year of retirement before Social Security and required distributions begin. Our posts on capital gains rates and the 2027 tax brackets show where the thresholds fall.
One side effect to plan for if you are on Medicare: a large gain raises your income for that year, which can raise your premiums two years later. See our post on the 2027 IRMAA brackets.
5. Defer the gain with a 1031 exchange
A like-kind exchange lets you swap one investment property for another without recognizing the gain at that time. The IRS page on like-kind exchanges notes that section 1031 now applies only to exchanges of real property, and the property must be held for use in a business or for investment. A main home does not qualify, and neither does property held primarily for sale, which rules out most flips.
The timeline is strict. Under the instructions for Form 8824:
- You must identify the replacement property within 45 days after you transfer the property you are giving up.
- You must receive the replacement within 180 days, or by the due date of your tax return including extensions, whichever is earlier.
Most exchanges run through a qualified intermediary who holds the sale proceeds. If you receive cash or other property that is not like-kind as part of the deal, you recognize gain up to that amount. The exchange is reported on Form 8824.
A 1031 exchange defers the tax. Your old basis carries into the new property, so the gain is still there when you eventually sell without exchanging.
6. Spread the gain with an installment sale
If the buyer pays you over time, you can report the gain over time. IRS Publication 537, Installment Sales, defines an installment sale as a sale where you receive at least one payment after the tax year of the sale. You figure the gain each year on the payments you receive and report it on Form 6252.
Spreading a gain across several years can keep more of it in a lower bracket and may keep your income under the net investment income tax thresholds. Two cautions apply. You are acting as the lender, so you carry the risk that the buyer stops paying. And for a rental, Publication 537 says you must report any depreciation recapture income in the year of sale, whether or not you received a payment that year.
The installment method can be combined with the home sale exclusion. Topic 701 confirms the exclusion remains available even if you use the installment method to defer some of the gain.
7. Offset the gain with capital losses
Capital losses from other investments reduce capital gains from real estate. If you have a losing stock position or a loss carried forward from an earlier year, it can absorb part of the gain. When losses exceed gains, Topic 409 says you can deduct up to $3,000 of the excess against other income ($1,500 if married filing separately) and carry the rest forward. Our guide to tax-loss harvesting explains how this works.
Two more situations that come up
Inherited property
Property you inherit generally takes a basis equal to its value at the date of death, not the price the original owner paid. If you sell soon after inheriting, there may be little gain to tax. Our inheritance guide covers this in more detail.
Opportunity zones
Investing a gain in a qualified opportunity fund within 180 days can defer it. The rules are changing. The IRS opportunity zones FAQ says that under the original program, deferral lasts until the earlier of the date you sell the fund investment or December 31, 2026, and Congress has since revised the program for later years. Get current guidance before relying on it.
Worked example: selling a long-held home
A married couple bought their home for $300,000 and added $50,000 of improvements over the years, including a new roof and a kitchen remodel. They sell for $950,000 and pay $57,000 in selling expenses.
- Amount realized: $950,000 minus $57,000 = $893,000
- Adjusted basis: $300,000 plus $50,000 = $350,000
- Gain: $893,000 minus $350,000 = $543,000
- Exclusion on a joint return: $500,000
- Taxable gain: $43,000
If the $43,000 falls in the 15% long-term bracket, the federal tax is $6,450. Without records of the improvements, the taxable gain would be $93,000 and the tax $13,950. State income tax may apply on top.
Worked example: selling a rental
An owner bought a rental for $200,000 and claimed $60,000 of depreciation, which lowers the adjusted basis to $140,000. The sale brings $400,000 after selling expenses.
- Total gain: $400,000 minus $140,000 = $260,000
- Portion from depreciation: $60,000, taxed at up to 25%
- Remaining $200,000: taxed at long-term rates
The home sale exclusion does not apply. The owner’s main options are a 1031 exchange into another investment property, an installment sale to spread the $200,000, or timing the sale for a low-income year. If a property was once your home and later a rental, the exclusion may cover part of the gain, but Publication 523 treats periods after 2008 when the property was not your main home as nonqualified use, with certain exceptions, and depreciation claimed is not excludable.
You can test your own figures with our Capital Gains Tax Calculator.
What to do before you sell
- Identify the property type: main home, rental, mixed use, inherited.
- For a home, count your months of ownership and residence in the last five years.
- Gather purchase documents and receipts for every improvement.
- For a rental, total the depreciation you have claimed.
- Estimate your other income for the year of sale and the year after.
- If you are considering a 1031 exchange, line up a qualified intermediary before closing. Once you receive the proceeds, it is too late.
- Run the numbers with a tax professional before you sign a contract.
Common mistakes
- Assuming you can avoid tax by buying another home. That rollover rule ended years ago. Today the exclusion is what applies to a main home.
- Selling at 23 months when one more month would have qualified for the full exclusion.
- Forgetting depreciation on a rental, or on a home office, when estimating the tax.
- Taking the sale proceeds yourself during a 1031 exchange.
- Missing the 45-day identification deadline.
- Not reporting the sale. Topic 701 says that if you receive Form 1099-S, you must report the sale even if the gain is excludable.
Frequently asked questions
How long do you have to live in a house to avoid capital gains tax?
At least 24 months out of the five years before the sale, and you must also have owned it for at least 24 months in that period. The months do not need to be consecutive.
Do I pay capital gains tax if I buy another house?
Buying another home does not defer the tax on your main home. You rely on the $250,000 or $500,000 exclusion. Only investment or business property can be exchanged tax-deferred under section 1031.
Is there a one-time capital gains exemption for people over 55?
No. There is no age-based exemption in current law. The home sale exclusion is available at any age and can be used more than once, as long as you have not used it in the previous two years.
How is the sale of a rental property taxed?
The gain attributable to depreciation is taxed at a maximum 25% rate, and the rest at long-term capital gains rates if you held the property more than one year. The 3.8% net investment income tax can apply at higher incomes.
Can I avoid capital gains tax on a second home?
Not with the home sale exclusion, unless you make it your main home and meet the two-year tests. You can still reduce the gain with improvements and selling costs, hold for long-term rates, use an installment sale or offset it with losses.
Next steps
- Work out your adjusted basis and likely gain before you list the property.
- Read our capital gains tax guide and our tax planning guide.
- Check the rate thresholds in our hub post on capital gains tax rates.
- If you want help deciding what to do with the proceeds or timing a sale around retirement, you can find a licensed financial advisor near you for a free conversation by phone or video call.
Run your numbers: use our free Capital Gains Tax Calculator to estimate the tax on a sale, or browse all our financial calculators.
Latest money guides and ideas
- Qualified Charitable Distribution Rules for 2026 and 2027Qualified charitable distribution rules let IRA owners aged 70 and a half or older give up to $111,000 in 2026 and $114,000 in 2027 to charity without counting it as income.
- Medicare Enrollment Periods and Late Penalties for 2027Medicare enrollment periods control when you can sign up and when coverage starts. Miss yours and Part B and Part D penalties can last for life. See the dates and 2027 costs.
- TSP Rollover to IRA: Should You Move Your TSP or Stay?A TSP rollover to an IRA is optional after you leave federal service. Compare costs, the G Fund, early access at 55 and withdrawal rules, then see how to move the money.
- Rollover IRA: How to Move an Old 401(k) Step by StepA rollover IRA holds money moved from an old 401(k). See your four options when you leave a job, how a direct rollover avoids tax, and the steps to move the account.
- Claiming Age Clarity Act: Social Security’s New Age TermsThe Claiming Age Clarity Act replaces full retirement age with standard monthly benefit age and renames ages 62 and 70. Your benefit amount and claiming rules do not change.
- States With Inheritance Tax: Rates and Who Pays in 2026Five states with inheritance tax remain: Kentucky, Maryland, Nebraska, New Jersey and Pennsylvania. See each state’s rates, who is exempt and worked examples.
- Treasury Bills: How to Buy T-Bills and How They Are TaxedTreasury bills are short-term U.S. government debt sold at a discount. Learn how T-bills pay interest, two ways to buy them, and how the interest is taxed.
- Is Long-Term Care Insurance Worth It? Cost and CoverageIs long-term care insurance worth it? See what a policy covers, what drives the premium, when to buy, who should skip it and the 2027 tax limits.
- Mega Backdoor Roth: How It Works and 2027 LimitsA mega backdoor Roth moves after-tax 401(k) contributions into a Roth account. See the 2027 limits, what your plan has to allow, worked examples and the steps.
Talk to a retirement planner near you
Free consultations by phone or video call.
- Retirement planning in Los Angeles
- Retirement planning in New York City
- Retirement planning in Chicago
- Retirement planning in Houston
- Retirement planning in Phoenix
- Retirement planning in Philadelphia
- Retirement planning in San Antonio
- Retirement planning in San Diego
- Retirement planning in Dallas
- Retirement planning in Austin
- Retirement planning in Jacksonville
- Retirement planning in San Jose









