Four years ago, a client of mine nearly fainted in my office. She'd sold her late mother's house for $612,000, paid off the mortgage, and then received a letter from the IRS asking about $180,000 in profit she never knew she'd made. She thought selling a family home meant closing a chapter. Turns out it also meant opening a tax file.
That moment is why I write about this. Because the gap between what people assume about capital gains tax when selling a home and what actually happens at the closing table is enormous. And the IRS doesn't send a friendly reminder before it becomes a problem.
Here's what most sellers get wrong: they confuse the concept of "profit" with the concept of "taxable gain." Those are not the same number. Not even close. In my first year doing this kind of consulting, I watched a seller assume he owed nothing because he'd "only made $40,000." He actually owed tax on nearly $190,000. The difference came down to basis, improvements, and one exclusion he didn't know existed.
Let me walk you through how this actually works, so you don't end up like either of them.
Key takeaways
- The Section 121 exclusion lets single filers shield up to $250,000 of gain, and married couples filing jointly up to $500,000 — but only if the home was your primary residence for 2 of the last 5 years.
- Your taxable gain isn't sale price minus purchase price. It's sale price minus selling costs, minus your adjusted basis, minus capital improvements you've documented.
- Rental properties, second homes, and inherited properties play by completely different rules — and the 1031 exchange is the tool most investors reach for.
- You can't "roll" a gain into your next home anymore. That rule died in 1997. Anyone who tells you otherwise is working from a very old playbook.
- Improvements add to basis; repairs don't. A new roof helps you. Fixing a leaky faucet doesn't.
- State-level capital gains tax can hit you even when federal tax doesn't. Some states have no income tax at all, which changes the math entirely.
How capital gains tax when selling a home actually works
When you sell real estate for more than you paid, the difference is a capital gain. Simple enough. The trouble starts when you try to define "more than you paid."
The IRS doesn't look at purchase price in isolation. It looks at your adjusted basis — your original cost plus the money you sank into the property that qualifies as a capital improvement. That basis gets subtracted from your net sale proceeds (sale price minus commissions, title fees, closing costs). The remainder is your gain.
What counts as your cost basis
The obvious answer is what you paid for the home. The less obvious answer includes things people forget about constantly:
- The original purchase price
- Certain closing costs from when you bought (title insurance, legal fees, recording fees — not things like homeowner's insurance or HOA dues)
- Capital improvements made during ownership
- Special assessments for local improvements like sidewalks or sewer lines
- Costs of restoring damage from a casualty loss, if you didn't claim a deduction
I once helped a seller reconstruct eight years of improvement receipts. We found $47,000 worth of legitimate additions — a new HVAC system, a kitchen remodel, a fence, and a full bathroom renovation. That $47,000 wiped out most of what she was going to owe. She nearly threw those receipts away two months earlier during a move.
Keep everything. That's the takeaway.
A worked example to see the numbers
Say you bought a home for $310,000. Over the years you put $60,000 into a kitchen and $15,000 into a new roof. Your adjusted basis is $385,000. You sell for $540,000, paying $32,400 in realtor commissions and $4,200 in closing costs. Your net proceeds are $503,400. Your gain is $118,400.
If that was your primary residence and you meet the two-out-of-five rule, that entire gain is excluded. You owe nothing federally. If it was a rental, you owe tax on the $118,400 — plus depreciation recapture on any depreciation you claimed along the way.
The Section 121 exclusion, explained properly
Here's the part most people have heard about but don't quite understand. Since the Taxpayer Relief Act of 1997, homeowners who sell their primary residence can exclude a chunk of gain from federal tax. Married couples filing jointly can exclude up to $500,000. Single filers can exclude up to $250,000.
Those numbers haven't moved in decades. Not indexed to inflation. Just frozen. Which means in a hot market, you can burn through that exclusion faster than you'd think.
The two-out-of-five year rule
To qualify, you must have owned the home and used it as your primary residence for at least two of the five years ending on the sale date. Those years don't have to be consecutive. But they do have to be real — a vacation home where you spend three weeks a year doesn't count.
And you can only use this exclusion once every two years. Sell two primary residences within a 24-month window and the second sale gets taxed normally.
What can be deducted from capital gains when selling a house
This is where I see the most wasted money. Sellers leave deductions on the table because they don't know they exist.
- Agent commissions and broker fees — typically the biggest single deduction, often 5-6% of sale price
- Title search and title insurance costs
- Escrow fees and attorney fees
- Recording fees and transfer taxes
- Advertising and marketing expenses you paid directly
- Any repairs made specifically to close the sale (what's sometimes called a "repair credit" negotiated with the buyer)
- Capital improvements made during ownership that increased the home's value
What doesn't count? Routine maintenance. Repainting a wall because it's faded. Fixing a garbage disposal. Replacing a worn-out water heater. These keep the home functional but they don't boost its value. They're expenses, not improvements, and the IRS treats them differently.
I learned that distinction the hard way when I first started. A client had spent $14,000 over three years on what he called "renovations" and was furious when I told him most of it couldn't be added to basis. Repairs. Every one of them.
How to avoid capital gains tax when selling a rental property
You don't get the Section 121 exclusion. That's the first thing to accept.
What you do get is the 1031 exchange, and it's a genuinely powerful tool. The rule lets you defer capital gains entirely if you reinvest the proceeds into a "like-kind" property — another investment property, essentially. You have 45 days to identify a replacement property and 180 days to close on it. Miss either deadline and the whole thing collapses.
The catch most people miss: 1031 exchanges defer, they don't eliminate. You'll eventually owe tax when you sell the final property for cash. Some investors keep rolling forward forever until they die, at which point the basis steps up for heirs. That's a strategy, not a loophole — and it requires actual planning, not improvisation.
Also, and this one stings: you'll owe depreciation recapture at a rate of up to 25% on any depreciation you claimed while renting the place out. Even in a 1031 exchange, some recapture rules apply.
Do I have to pay capital gains if I sell my house and buy another?
This question comes up constantly, and I understand why. There was a time when you could roll the gain from one home into another and defer the tax indefinitely. That was called the "rollover rule," and it applied to anyone 55 or older who was buying a replacement residence.
It was repealed in 1997.
Since then, buying another house has zero effect on your capital gains tax on the one you sold. None. You're taxed on the sale of the first house based on whether that first house qualified for the Section 121 exclusion. The second house is a second house, full stop.
I've had to explain this to more people than I can count. They buy the new home and think the paperwork is somehow connected. It isn't. Unless you're specifically doing a 1031 exchange with an investment property — a different situation entirely — the two transactions are completely independent for tax purposes.
How to avoid capital gains tax when selling a home
Let me be clear from the start: "avoid" is a loaded word. Some of what passes for advice out there is tax evasion dressed up in nicer language. I'm not going to write that. What I will do is walk you through legitimate strategies the IRS actually allows.
Qualify for the primary residence exclusion
This is the big one. If you've lived in the home for two of the last five years, you're almost certainly eligible for the $250,000 or $500,000 exclusion. Document your residency. Keep utility bills, tax returns, and driver's license records. If the IRS audits you years later, proving where you lived matters.
Document your capital improvements
Every dollar of legitimate improvement adds to basis and reduces gain. New roof, new HVAC, an addition, a major landscaping overhaul that's structural, a complete kitchen or bathroom remodel, replacement windows, a new septic system. Keep receipts. Keep contractor invoices. Take photos. This is boring advice and it's the single biggest reason people overpay.
Time your sale strategically
If you're close to the two-year threshold, waiting a few months can be worth a fortune. If you're close to the five-year window and you've been renting the place out partway through, look carefully at what counts as "use as a primary residence." The rules get finicky around partial rental periods, and getting the timing wrong can cost you the exclusion entirely.
Handle a deceased spouse or divorce carefully
These situations have special rules, and they're worth knowing about even if you hope never to need them.
If your spouse passed away, you may qualify for the full $500,000 exclusion on a sale within two years of the death, even if you file as single. It's called the "surviving spouse" rule.
In a divorce, the spouse who moves out may be able to count time lived in the home by the spouse who stayed. This preserves eligibility for the exclusion in situations where it would otherwise be lost.
If you inherited the property, your basis generally steps up to the fair market value on the date of death. That often eliminates a huge chunk of taxable gain, sometimes all of it. A house worth $150,000 when you inherited it and sold for $180,000 two years later shows a gain of $30,000 — not the gain measured against what the deceased originally paid decades earlier.
How to avoid capital gains tax over 65
The old "over 55" rule that gave a one-time $125,000 exclusion was eliminated in 1997 as well. There's no age-based exclusion anymore.
What does exist for older sellers is more about planning than special exemptions. The Section 121 exclusion is the same for a 68-year-old as it is for a 35-year-old. What changes is that many older sellers hold homes with very low basis — purchased decades ago — and the gain is often huge. In those cases, the $250,000 or $500,000 exclusion does a lot of heavy lifting, but it might not cover everything.
Some sellers in this situation consider staying in the home until death, which triggers a step-up in basis for heirs and eliminates capital gains entirely. Others sell and accept the tax. Neither is wrong. What matters is knowing the options.
Comparing the three main scenarios
Here's a side-by-side that lays out how different property types are treated.
| Scenario | Section 121 exclusion? | Depreciation recapture? | 1031 exchange available? |
|---|---|---|---|
| Primary residence (2+ years owned/occupied) | Yes — up to $250K/$500K | Only if used as rental previously | No (not needed) |
| Second home / vacation property | No, unless it was your primary residence 2 of 5 years | No (unless previously rented) | No — must be investment property |
| Rental / investment property | No | Yes — up to 25% on prior depreciation | Yes — most common path |
One thing I want to add: the lines blur more than the table suggests. A rental property that you move into for two years before selling can qualify for the primary residence exclusion. A primary residence you rent out for three years and then move back into can also qualify. The rules around partial use are where most of the complexity lives, and where a good CPA earns their fee.
Who pays property taxes when selling a house?
Property taxes are prorated at closing. The seller typically pays for the portion of the year they owned the home, and the buyer pays for the portion after closing. If the seller already paid the full year upfront — which happens in many jurisdictions — the buyer reimburses them at closing for their share.
This isn't a capital gains issue directly, but it does affect your net proceeds calculation. Anything that changes how much cash you walk away with can shift whether you have a taxable gain.
Also worth knowing: any unpaid property taxes become a lien on the property at closing and must be settled for the sale to go through. If you're behind on property taxes, they get paid off before you see a dime of proceeds.
Do you really need a calculator?
There are plenty of online capital gains calculators out there, and some are decent. I've used a few. But here's the honest truth from someone who's walked sellers through this dozens of times: the calculator only works if you've done the work upfront.
You need to know your adjusted basis. That means knowing every capital improvement you've made, every cost that qualifies for addition to basis, and every selling expense. If you plug in the wrong numbers, the calculator gives you a confident wrong answer.
I've seen calculators correctly apply the Section 121 exclusion and then mislead someone because they didn't know about depreciation recapture on a property they'd rented for two years. The number looked clean. The tax bill wasn't.
Use the calculators as a starting point. Then talk to someone who does this professionally. The $300 or $500 you spend on a consultation is worth it when the stakes are tens of thousands of dollars.
And keep every receipt. Every single one.
Because the difference between a smooth sale and a nightmare usually comes down to whether you can prove, on paper, what you spent. My client with the $47,000 in improvement receipts? She sat in my office with a folder she'd almost thrown away. If she had, she'd have written a check to the IRS for more than $8,000.
She didn't. Because she kept the folder.