How to Avoid Capital Gains Tax on Your Home Sale
Legal strategies East Bay homeowners can use to avoid capital gains tax on a home sale, from the primary residence exclusion to cost-basis adjustments.
TL;DR: Most East Bay homeowners can exclude the entire gain on a home sale from federal income tax — up to $250,000 for single filers or $500,000 for married couples filing jointly — by meeting two straightforward tests [1]. When the gain exceeds the exclusion, cost-basis adjustments, selling-cost deductions and strategic timing can shrink or eliminate the taxable remainder. Understanding these rules before you list is the difference between a surprise tax bill and a clean closing.
Key Takeaways
- You may exclude up to $250,000 of capital gain from income on the sale of your main home, or up to $500,000 if you file a joint return with your spouse [1].
- The exclusion requires that you owned and used the home as your primary residence for at least two of the five years before the sale.
- Your taxable gain is the selling price minus deductible closing costs, selling costs and your adjusted cost basis — not simply the difference between what you paid and what you received.
- A 1031 exchange can defer capital gains on investment property, but it does not apply to a primary residence.
- East Bay home values have risen steeply over the past two decades, which makes basis adjustments and selling-cost documentation more important than ever for local sellers.
How Does the Primary Residence Exclusion Work?
The single largest tool for avoiding capital gains tax on a home sale is the federal primary residence exclusion under Section 121 of the Internal Revenue Code. If you have a capital gain from the sale of your main home, you may qualify to exclude up to $250,000 of that gain from your income, or up to $500,000 of that gain if you file a joint return with your spouse [1].
To qualify, you must meet both the ownership test and the use test. You meet the ownership test if you owned the home for at least 24 months out of the last five years leading up to the date of the sale. You meet the use test if you used the home as your residence for at least 24 months of the previous five years. The two periods do not need to overlap — you can meet each test during different two-year windows within that five-year span.
For married couples filing jointly, only one spouse needs to satisfy the ownership test, but both must independently meet the use test. You can generally claim the exclusion once every two years.
For most families who have lived in their Alamo, Danville or Walnut Creek home for several years, these tests are met automatically. The exclusion applies whether you buy another home afterward or not — there is no reinvestment requirement under the current law.
What Counts Toward Your Cost Basis?
Many sellers underestimate their cost basis and overestimate their taxable gain as a result. Your gain is your home’s selling price, minus deductible closing costs, selling costs and your tax basis in the property. Your basis is the original purchase price, plus the cost of capital improvements, minus any depreciation.
Capital improvements are projects that add value, extend the home’s useful life or adapt it to a new use. In the East Bay, common improvements that raise your basis include:
- Kitchen and bathroom remodels — gut renovations, not cosmetic updates
- Room additions or ADU construction — increasingly common in Walnut Creek and Lafayette
- New roof, HVAC, or foundation work — structural upgrades that extend the home’s life
- Seismic retrofitting — a frequent investment in older Contra Costa homes
- Landscaping and hardscaping — retaining walls, drainage systems, permanent outdoor structures
Keep every receipt, permit record and contractor invoice. If you have owned your home for a long time, those accumulated improvements may represent a significant upward adjustment to your basis — and a corresponding reduction in your taxable gain.
What About Selling Costs?
Selling costs also reduce your gain. Deductible selling costs include real estate broker commissions, title insurance, legal fees, advertising costs, administrative costs and inspection fees. The IRS also recognizes that costs ordinarily attributed to decorating or repairs — painting, wallpapering, planting flowers — qualify as selling costs if you complete them within 90 days of the sale and with the intention of making the home more saleable.
This is one reason we encourage sellers to document every dollar spent preparing a home for market. The staging, the landscaping refresh, the interior paint — each receipt directly reduces the taxable gain.
Can a 1031 Exchange Help Me Avoid Capital Gains Tax?
A 1031 exchange allows you to defer capital gains tax by reinvesting the proceeds from the sale of an investment or business property into a like-kind replacement property. It is one of the most powerful tools in real estate — but it does not apply to your primary residence.
If you own rental property along the I-680 corridor and are planning to sell, a 1031 exchange lets you roll the gain into a replacement investment property and defer the tax indefinitely. The rules are strict: you must identify replacement properties within 45 days and close within 180 days, and the exchange must be handled through a qualified intermediary. The proceeds cannot touch your bank account.
For homeowners selling a primary residence, the Section 121 exclusion is the relevant provision — not the 1031 exchange. The two provisions serve different property types and different strategies.
| Strategy | Applies To | How It Works | Key Requirement |
|---|---|---|---|
| Section 121 exclusion | Primary residence | Excludes gain from income entirely | Own and live in home 2 of last 5 years |
| Cost-basis adjustment | Any property | Raises basis, shrinks taxable gain | Documented capital improvements |
| Selling-cost deduction | Any property | Subtracts commissions, fees, prep costs from gain | Receipts and records |
| 1031 exchange | Investment property only | Defers gain into replacement property | 45-day ID, 180-day close, qualified intermediary |
| Installment sale | Any property | Spreads gain recognition across tax years | Seller-financed terms in the contract |
What If My Gain Exceeds the Exclusion?
In high-appreciation markets like Alamo and Danville, long-held properties can produce gains that exceed the exclusion thresholds. When that happens, the portion above the exclusion is subject to federal capital gains tax — and to California state income tax, which treats capital gains as ordinary income.
The first step is to calculate your actual gain accurately. Sellers often assume the gain is the simple difference between purchase price and sale price, but that ignores improvements, selling costs and basis adjustments. As one source illustrates, a couple who bought a home, added capital improvements and paid broker commissions and preparation costs could find that the exclusion and those deductions together eliminate the entire taxable gain.
Before you list, sit down with a CPA or tax advisor and run the numbers with your real documentation. The exercise almost always produces a smaller taxable figure than the back-of-envelope estimate.
Installment Sales
If you sold your home under a contract that provides for all or part of the selling price to be paid in a later year, you made an installment sale. Installment sales spread the gain recognition across multiple tax years, which can keep you in a lower bracket in any single year. This strategy is less common in the East Bay’s competitive market — most buyers use conventional financing — but it is worth understanding if you are selling a high-value property to a family member or in an off-market transaction.
What If I Don’t Meet the Full Ownership and Use Tests?
You may still qualify for a partial exclusion if you sold the home due to a change in employment, health reasons or certain unforeseen circumstances. The partial exclusion is prorated based on the fraction of the two-year requirement you did meet.
Unmarried co-owners who jointly own a home and separately meet the ownership and use tests can each exclude up to $250,000 of their share of the gain [2]. This matters for siblings who inherited a property, domestic partners or friends who purchased together.
Military families have an additional provision: if you or your spouse are on qualified official extended duty in the Uniformed Services, the Foreign Service or the intelligence community, you may elect to suspend the five-year test period for up to 10 years. Qualified official extended duty means a duty station at least 50 miles from your main home, or residing in government housing under government orders, for more than 90 days or an indefinite period.
How Does Prop 19 Affect Capital Gains Planning in California?
Prop 19, which took effect in 2021, changed property tax reassessment rules for homeowners over 55, those with severe disabilities and wildfire victims. It allows eligible homeowners to transfer their existing Prop 13 property tax base to a replacement home anywhere in California — up to three times.
Prop 19 does not change your federal or state capital gains tax. It affects your ongoing property tax, not the tax owed at the point of sale. But it matters for planning because it removes a common reason sellers stay put. Before Prop 19, many long-time East Bay homeowners avoided selling because buying a replacement home meant a dramatically higher property tax bill. That lock-in effect kept people in homes they had outgrown. With the base transfer now available statewide, the decision to sell can focus on the capital gains math and the market timing rather than the property tax fear.
For a deeper look at Mello-Roos and special tax districts that may affect your net proceeds, see our post on what Mello-Roos means for East Bay homeowners.
Why This Matters
As of November 2026, East Bay home values remain well above where most long-term owners purchased. A family that bought in Alamo or Danville in the late 1990s or early 2000s is sitting on substantial appreciation. Our team’s sold record in Alamo alone covers 219 closed MLS transactions totaling $261.7 million, with a median sale price of $1,115,000. In Danville, 202 closed transactions totaling $186.7 million carry a median of $855,000. Those medians reflect the kind of values that make capital gains planning essential — not optional.
The federal exclusion thresholds have not been adjusted for inflation since they were set in 1997, while Bay Area home prices have climbed dramatically. That gap means more sellers will see gains that approach or exceed the exclusion, and documentation of improvements and selling costs becomes the difference between a taxable event and a clean exclusion.
If you are considering a sale and want to understand where you stand, request a free home valuation so you can run the capital gains math with a realistic market price — not a Zestimate. We have been helping East Bay families navigate these decisions since 1985, and the conversation always starts with the numbers.
Sources
[1] irs.gov, “Topic no. 701, Sale of your home | Internal Revenue Service”. https://www.irs.gov/taxtopics/tc701
[2] hd.carelonwellbeing.com, “Avoiding Capital Gains Tax When Selling Your Home: Read the Fine Print - Home Depot EAP | Carelon”. https://hd.carelonwellbeing.com/hd/find-legal-support/resources/taxes-and-audits/legal-assist/avoiding-capital-gains-tax-when-selling-your-home-read-the-fine-print
Frequently Asked Questions
Can I avoid capital gains tax by buying another house?
For your primary residence, buying another house does not defer the gain the way it did before 1997. The current law provides an exclusion you can claim every two years as long as you meet the ownership and use tests — regardless of whether you purchase a replacement home. A 1031 exchange can defer the gain on an investment property, but it does not apply to your personal residence.
Do home improvements reduce capital gains tax when I sell?
Yes. Capital improvements — a new roof, a kitchen remodel, an added bathroom — increase your cost basis. A higher basis means a smaller taxable gain. Keep receipts and contractor invoices for every project. Routine maintenance like painting or fixing a leaky faucet does not count as a capital improvement, but repairs made within ninety days of the sale to make the home more saleable may qualify as selling costs.
What happens if only one spouse meets the ownership test?
If you file jointly, only one spouse needs to meet the ownership test, but both must independently meet the use test — meaning both lived in the home as a primary residence for at least two of the five years before the sale. When both tests are satisfied, the couple can claim the full joint exclusion.
Does California tax capital gains on a home sale differently than the federal government?
California taxes capital gains as ordinary income at the state level and does not offer a separate state-level exclusion beyond the federal one. The federal primary residence exclusion still applies, so the same gain that is excluded federally is also excluded from California income tax. Any gain above the exclusion is added to your California adjusted gross income.