Every time you sell an investment for a profit, the IRS wants a cut. But the tax code is filled with provisions that let you legally reduce, defer, or completely eliminate that bill. Learning how to avoid capital gains tax isn’t about gaming the system. It’s about using the rules the way they were designed to be used.
In 2026, long-term capital gains rates sit at 0%, 15%, or 20% depending on your taxable income, while short-term gains are taxed at ordinary income rates as high as 37%. Add the 3.8% net investment income tax for high earners, and the effective top rate on investment profits hits 23.8%. That’s a lot of money walking out the door if you aren’t planning ahead.
Here are nine strategies that can keep more of your gains where they belong.
1. Hold Investments for More Than One Year
This is the simplest and most powerful move available. The IRS taxes short-term capital gains (assets held one year or less) at ordinary income rates, which range from 10% to 37% in 2026. Hold that same asset for more than 12 months, and the rate drops to 0%, 15%, or 20% under the long-term capital gains brackets.
The math is straightforward. Say you’re a single filer earning $180,000 in salary and you sell a stock for a $40,000 gain. If you held it for 11 months, that gain gets taxed at your marginal ordinary income rate of 32%, costing you $12,800 in federal tax. Hold it one more month and the long-term rate of 15% applies, bringing the bill down to $6,000. That’s $6,800 saved by waiting a few extra weeks.
For 2026, single filers with taxable income below approximately $48,350 pay 0% on long-term gains. Between $48,350 and $533,400, the rate is 15%. Above $533,400, it’s 20%. Married couples filing jointly get wider brackets: 0% up to about $96,700 and 15% up to $583,750. You can check the exact thresholds for your filing status in our 2026 federal income tax brackets guide.
If you’re sitting on a winner and you’re close to the one-year mark, set a calendar reminder. Patience is one of the most overlooked tax strategies in existence.
2. Tax-Loss Harvesting
Tax-loss harvesting is the practice of deliberately selling investments that have declined in value to generate realized losses, which then offset your capital gains. If you’ve got $30,000 in gains and $18,000 in unrealized losses elsewhere in your portfolio, selling those losers brings your taxable gain down to $12,000.
The strategy goes further. If your capital losses exceed your capital gains in a given year, you can deduct up to $3,000 of the excess against ordinary income ($1,500 if married filing separately). Any remaining losses carry forward to future tax years indefinitely, which means a bad year in the market can create a tax asset you’ll use for years.
There’s one critical rule to follow: the wash sale rule. If you sell a security at a loss and buy back the same or a “substantially identical” security within 30 days before or after the sale, the IRS disallows the loss. The window covers 61 days total. You don’t lose the deduction permanently — the disallowed loss gets added to the cost basis of the replacement shares — but it kills the tax benefit for the current year.
The workaround is straightforward. Sell the losing position and immediately buy something similar but not identical. Swap an S&P 500 index fund for a total stock market fund. Replace one large-cap growth ETF with another from a different provider tracking a different index. You stay invested in roughly the same asset class while locking in the tax loss.
For a deeper dive on how gains and losses interact, see our capital gains tax calculator guide.
3. Use Tax-Advantaged Accounts
The most permanent way to avoid capital gains tax is to never owe it in the first place. Tax-advantaged retirement accounts let you do exactly that.
Roth IRA. Contributions go in with after-tax dollars, but all growth and qualified withdrawals are completely tax-free. You’ll never pay capital gains tax on profits earned inside a Roth, no matter how large they get. In 2026, the Roth IRA contribution limit is $7,000 ($8,000 if you’re 50 or older). Income limits apply for direct contributions, but the backdoor Roth strategy remains available for higher earners. Over a 30-year career, the compounding effect of tax-free growth is enormous.
Traditional IRA and 401(k). Contributions may be tax-deductible, and investment gains grow tax-deferred. You won’t owe capital gains tax as you buy and sell within the account. The trade-off is that withdrawals in retirement are taxed as ordinary income. For 2026, the 401(k) employee contribution limit is $23,500 ($31,000 with catch-up contributions for those 50 and over). The IRS retirement contribution limits page has the full breakdown.
Health Savings Account (HSA). If you have a high-deductible health plan, the HSA is arguably the most tax-efficient account in the entire code. Contributions are tax-deductible, growth is tax-free, and withdrawals for qualified medical expenses are tax-free. That’s a triple tax benefit no other account offers. In 2026, you can contribute $4,300 for individual coverage or $8,550 for family coverage. Many people use their HSA as a stealth retirement account by paying medical bills out of pocket now and letting the HSA balance compound for decades.
Smart asset location. Beyond just contributing to these accounts, think about which investments go where. Hold tax-inefficient assets (actively traded funds, REITs, taxable bonds) inside tax-advantaged accounts. Keep buy-and-hold index funds in your taxable brokerage, where they generate fewer taxable events and qualify for long-term rates when you eventually sell.
4. The Primary Residence Exclusion
If you’ve owned and lived in your home as your primary residence for at least two of the five years before selling, you can exclude up to $250,000 of capital gains from tax ($500,000 for married couples filing jointly). This provision, codified in IRS Publication 523, is one of the most generous tax breaks available to individuals.
You don’t need to have lived there for two consecutive years. The 24-month requirement can be met in any combination of months during the five-year lookback period. And you can use this exclusion once every two years, so it’s a repeatable benefit for people who move regularly.
Here’s what that looks like in practice. You bought a house in 2020 for $350,000 and sell it in 2026 for $650,000. That’s a $300,000 gain. If you’re single, $250,000 is excluded and you pay capital gains tax on the remaining $50,000. If you’re married filing jointly, the entire $300,000 gain is excluded and you owe nothing.
A few nuances to watch:
Partial exclusion. If you don’t meet the full two-year requirement because of a job relocation, health issue, or other qualifying circumstance, you may still qualify for a partial exclusion proportional to the time you lived there.
Depreciation recapture. If you rented out the home for any period and claimed depreciation, that depreciated amount is subject to recapture at a maximum rate of 25%, even if the rest of your gain qualifies for the exclusion.
Mixed-use periods. Under the rules finalized in prior years, any gain allocated to periods of non-qualified use (generally time the property wasn’t your primary residence, excluding periods before 2009) doesn’t qualify for the exclusion. This matters for people who converted a rental property into a primary residence to capture the exclusion.
5. 1031 Like-Kind Exchange for Real Estate
Section 1031 of the Internal Revenue Code lets you defer capital gains tax entirely when you sell an investment property and reinvest the proceeds into another “like-kind” property. There’s no limit on how many times you can do this, which means savvy real estate investors can defer gains for decades, potentially forever.
The rules are strict:
Like-kind requirement. Both properties must be held for investment or business use. You can’t 1031 exchange into a personal residence. But “like-kind” is interpreted broadly for real estate: you can swap a rental apartment building for raw land, a commercial office for a warehouse, or a single-family rental for a multifamily complex.
Timeline. You have 45 days from the sale of your relinquished property to identify up to three potential replacement properties (or more under certain valuation rules). You must close on the replacement property within 180 days. Miss either deadline and the entire exchange fails.
Qualified intermediary. You can’t touch the proceeds. A qualified intermediary must hold the funds between the sale and the purchase. If the money hits your bank account, the exchange is disqualified.
Equal or greater value. To defer the full gain, the replacement property must be of equal or greater value, and you must reinvest all the net proceeds. If you pull cash out (called “boot”), that amount is taxable.
Many investors chain 1031 exchanges throughout their careers, continuously trading up to larger properties and deferring gains along the way. When combined with the step-up in basis at death (covered below), the deferred gains can potentially disappear entirely.
One important limitation: since the Tax Cuts and Jobs Act of 2017, 1031 exchanges are limited to real property. Personal property, art, equipment, and other non-real-estate assets no longer qualify.
6. Invest in Qualified Opportunity Zones
The Opportunity Zone program, created by the Tax Cuts and Jobs Act, offers tax incentives for investing capital gains in designated economically distressed communities. There are over 8,700 designated zones across all 50 states and territories.
Here’s how it works in 2026:
Deferral of existing gains. When you realize a capital gain from any source (stocks, real estate, a business sale), you can invest that gain into a Qualified Opportunity Fund (QOF) within 180 days. The original gain is deferred until you sell the QOF investment or December 31, 2026, whichever comes first. The original deferral deadline has now arrived, meaning deferred gains from the program’s early years will come due on 2026 returns unless the investment is still held in certain structures.
Tax-free appreciation. This is the real prize. If you hold the Opportunity Zone investment for at least 10 years, any appreciation on the new investment is permanently excluded from capital gains tax. For investments made in the program’s early years that have appreciated significantly, this benefit is substantial.
The rules are complex and have been subject to ongoing IRS guidance. The IRS Opportunity Zones resource page and Form 8996 cover the compliance requirements for Qualified Opportunity Funds. This isn’t a DIY strategy for most people. It typically requires working with a tax advisor and an investment manager familiar with the program’s requirements.
7. Donate Appreciated Assets to Charity
If you’re already planning to make charitable contributions, donating appreciated assets instead of cash can eliminate capital gains tax on the appreciation while simultaneously generating an itemized deduction.
Here’s the mechanics. You own stock you bought for $10,000 that’s now worth $50,000. If you sell the stock and donate the cash, you’d owe capital gains tax on the $40,000 gain and then donate the after-tax proceeds. Instead, donate the stock directly to a qualified 501(c)(3) organization. You pay zero capital gains tax and you get a charitable deduction for the full $50,000 fair market value.
The requirements:
Holding period. The asset must have been held for more than one year. If you donate short-term holdings, your deduction is limited to your cost basis, not the fair market value.
AGI limits. Deductions for appreciated capital gain property donated to public charities are generally limited to 30% of your adjusted gross income. Contributions exceeding this limit can be carried forward for up to five years.
Donor-advised funds (DAFs). If you don’t have a specific charity in mind or you want to spread your giving over time, you can contribute appreciated assets to a donor-advised fund. You get the tax deduction in the year of contribution and then recommend grants to specific charities over the coming years. Major providers like Fidelity Charitable, Schwab Charitable, and Vanguard Charitable make this process simple.
Bunching strategy. With the standard deduction at $15,000 for single filers and $30,000 for married couples in 2026, many people don’t have enough itemized deductions to clear the threshold in any given year. Bunching two or three years of charitable contributions into a single year (via a donor-advised fund) can push you over the standard deduction in that year while you take the standard deduction in the off years.
8. Gift Appreciated Assets to Family Members in Lower Tax Brackets
If you have family members in lower income tax brackets, transferring appreciated assets to them before selling can result in a lower capital gains tax rate, or potentially no tax at all.
Remember those 0% long-term capital gains brackets? In 2026, a single filer with taxable income under roughly $48,350 pays zero capital gains tax on long-term gains. For married couples filing jointly, the 0% threshold is about $96,700. If your adult child, retired parent, or other family member falls under those thresholds, a gifted asset they sell could be entirely tax-free.
There are rules and limits:
Annual gift tax exclusion. In 2026, you can give up to $19,000 per recipient ($38,000 for married couples giving jointly) without triggering any gift tax reporting obligation. The IRS gift tax FAQ covers the mechanics.
Carryover basis. When you gift an appreciated asset, the recipient generally takes your original cost basis and holding period. They’re inheriting your unrealized gain. If they sell at a higher price, they’ll owe tax on the difference between your original basis and their sale price, but at their rate, not yours.
Kiddie tax. For children under 19 (or under 24 if a full-time student), unearned income above $2,500 in 2026 is taxed at the parent’s marginal rate under the kiddie tax rules. This effectively blocks the strategy for minor children and most college-age dependents. It works best with adult family members who have their own low-income situations.
Lifetime exemption. Gifts exceeding the annual exclusion count against your lifetime estate and gift tax exemption, which is $13.99 million per individual in 2026. For most people, this isn’t a binding constraint, but it’s worth tracking.
This strategy isn’t just about saving money. It can also be a practical way to help family members who could use the proceeds more than you could, while structuring the transfer in a tax-efficient way.
9. Step-Up in Basis at Death
This isn’t a strategy you can use during your lifetime, but it’s arguably the most powerful capital gains provision in the entire tax code, and it should shape how you think about estate planning and asset selection.
When you die, the cost basis of your assets “steps up” to their fair market value on the date of death. Under IRS Publication 559, your heirs inherit the asset at that stepped-up basis, which means all the appreciation that occurred during your lifetime is never subject to capital gains tax.
The implications are massive. Say you bought Amazon stock for $5,000 twenty years ago and it’s now worth $500,000. If you sell it, you owe capital gains tax on $495,000 of appreciation. But if your heirs inherit it, their cost basis resets to $500,000. They could sell it the next day and owe nothing.
This is why many financial advisors recommend against selling highly appreciated assets in retirement if you don’t need the proceeds. Holding those assets and letting the step-up in basis wipe out the gain can save a family hundreds of thousands of dollars.
It also explains why the 1031 exchange strategy is so powerful for real estate investors. You defer gains through successive exchanges during your lifetime, and then the step-up in basis at death permanently eliminates the accumulated deferred gains for your heirs.
Community property bonus. In community property states (Arizona, California, Idaho, Louisiana, Nevada, New Mexico, Texas, Washington, and Wisconsin), both halves of community property get a full step-up when one spouse dies. In common law states, only the deceased spouse’s half receives the step-up. This is a meaningful planning consideration for married couples with significant jointly held assets.
Current legislative risk. The step-up in basis has been a target in multiple recent budget proposals. There have been proposals to eliminate or cap the step-up, particularly for very large estates. As of April 2026, the provision remains fully intact, but it’s worth monitoring. Any changes would significantly alter long-term estate and investment planning.
The Net Investment Income Tax: An Extra Layer for High Earners
Any discussion of how to avoid capital gains tax should address the 3.8% net investment income tax (NIIT). Under IRS Form 8960 rules, the NIIT applies to individuals with modified adjusted gross income above $200,000 (single) or $250,000 (married filing jointly).
The NIIT covers capital gains, dividends, interest, rental income, and royalties. It effectively pushes the top long-term capital gains rate from 20% to 23.8%. These thresholds have never been adjusted for inflation since the tax was introduced in 2013, which means more taxpayers cross them every year.
Strategies that reduce your MAGI (such as maximizing pre-tax retirement contributions or timing income recognition) can help you stay below the NIIT threshold. Roth conversions, while temporarily increasing MAGI, can reduce future NIIT exposure by lowering required minimum distributions later.
Combining Strategies for Maximum Impact
These nine strategies aren’t mutually exclusive. The most effective tax planning combines several of them.
A real estate investor might use a 1031 exchange to defer gains on a property sale, reinvest in an Opportunity Zone to capture tax-free appreciation on the new investment, and ultimately pass the holdings to heirs who benefit from the step-up in basis.
A stock investor might harvest losses in a down year to offset gains, donate their most appreciated holdings to a donor-advised fund, hold remaining positions for over a year to qualify for long-term rates, and keep tax-inefficient assets inside a Roth IRA.
A retiree might sell their primary residence tax-free under the $250,000/$500,000 exclusion, gift some appreciated securities to adult children in lower brackets, and leave the rest for the step-up in basis.
The key is working with a qualified tax advisor who can model your specific situation. The cost of professional tax planning is almost always dwarfed by the savings it produces.
Frequently Asked Questions
Is it legal to avoid capital gains tax?
Yes. There’s a critical difference between tax avoidance and tax evasion. Tax avoidance means using legal provisions in the tax code to minimize your bill, and it’s perfectly legal. Tax evasion means hiding income or lying on your return, which is a federal crime. Every strategy in this article is explicitly provided for in the Internal Revenue Code and IRS regulations. The tax code was designed with these incentives to encourage specific behaviors like long-term investing, charitable giving, homeownership, and retirement savings.
What is the capital gains tax rate for 2026?
Short-term capital gains (assets held one year or less) are taxed at ordinary income rates ranging from 10% to 37%. Long-term capital gains (assets held more than one year) are taxed at 0%, 15%, or 20%, depending on your taxable income and filing status. Single filers earning up to about $48,350 in taxable income pay 0%. Between $48,350 and $533,400, the rate is 15%. Above $533,400, it’s 20%. High earners may also owe the 3.8% net investment income tax on top of these rates. See our 2026 tax brackets breakdown for complete details.
Can you avoid capital gains tax on stocks without selling?
You can’t trigger capital gains tax if you don’t sell. Unrealized gains (paper profits on stocks you still hold) aren’t taxable under current law. But “not selling” isn’t always a viable strategy. Alternatives include donating appreciated stock to charity, gifting shares to family members in lower brackets, holding shares until death so heirs receive a stepped-up basis, or harvesting losses on other positions to offset gains when you do sell.
How does the 1031 exchange work for real estate?
A 1031 exchange lets you sell an investment property and defer capital gains tax by reinvesting the proceeds into another like-kind property. You must identify a replacement property within 45 days and close within 180 days. The funds must be held by a qualified intermediary (you can’t touch them directly). Both properties must be held for investment or business use, not personal use. If you reinvest the full proceeds into a property of equal or greater value, the entire gain is deferred. You can chain these exchanges indefinitely, and the deferred gains may ultimately be eliminated through the step-up in basis at death.
What is the wash sale rule and how do you avoid triggering it?
The wash sale rule prevents you from claiming a tax loss if you buy back the same or a “substantially identical” security within 30 days before or after the sale. The 61-day window is enforced across all your accounts, including IRAs. To stay compliant while maintaining market exposure, replace the sold security with something similar but not identical. For example, swap an S&P 500 ETF for a total stock market ETF, or replace one tech-sector fund with another that tracks a different index. Wait at least 31 days if you want to buy back the exact same security.
Do you pay capital gains tax on inherited property?
Generally, no, at least not on gains that occurred during the deceased person’s lifetime. Inherited assets receive a “step-up in basis” to their fair market value on the date of death. If you inherit stock that was originally purchased for $20,000 and is worth $200,000 when the owner dies, your cost basis is $200,000. If you sell it for $205,000, you’d only owe capital gains tax on the $5,000 of post-inheritance appreciation. This provision effectively eliminates capital gains tax on a lifetime of growth and is one of the most significant wealth-transfer benefits in the tax code.