How to Avoid Capital Gains Tax: 12 Legal Strategies That Actually Work
Learn 12 proven legal strategies to reduce or avoid capital gains tax. Covers holding periods, tax loss harvesting, the 0% bracket, Section 121 home exclusion, 1031 exchanges, Opportunity Zones, installment sales, charitable giving, donor-advised funds, and retirement contributions — all with real numbers and examples.

You Are Probably Paying More Capital Gains Tax Than You Have To
I review tax returns for a living. After twelve years of doing this, one pattern shows up again and again: people pay thousands more in capital gains tax than the law requires. Not because they are doing anything illegal. Because they do not know the rules that were written specifically to help them pay less.
A client named Robert came to me last year after selling stock for a $120,000 gain. He assumed the tax would be around $18,000 at the 15% rate. His actual bill came to $36,000 — nearly double what he expected. Why? He held the stock for eleven months, making it a short-term gain taxed at ordinary rates. If he had waited just one more month, his tax would have dropped to $18,000. One month cost him $18,000.
That single mistake is more common than you think. And there are dozens of similar traps that cost people money every single year. The good news is that the Internal Revenue Code is full of provisions designed to reduce your capital gains tax burden. You just have to know they exist and use them correctly.
This guide covers twelve strategies that are completely legal, well-established, and available to any taxpayer who qualifies. No loopholes. No sketchy deductions. Just the rules as written, explained with real numbers so you can see exactly how much you can save.
Use our capital gains tax calculator to see your current tax bill, then apply these strategies to see how much lower it can go.
1. Hold Investments for More Than One Year
This is the simplest and most powerful strategy on the list. The difference between short-term and long-term capital gains rates can be staggering.
Short-term gains — from assets held for one year or less — get taxed at ordinary income rates. Those rates run from 10% up to 37%. Long-term gains — from assets held for more than one year — get taxed at 0%, 15%, or 20%. The gap between the two can exceed 20 percentage points.
Let me show you the math. Say you are a single filer with $150,000 in ordinary income and you sell a stock for a $50,000 gain. If you held it for eleven months, that $50,000 gets stacked on top of your salary and taxed at the 24% ordinary rate. Your tax on the gain is $12,000. If you held it for thirteen months instead, the gain falls into the 15% long-term bracket. Your tax drops to $7,500. That extra two months of patience saves you $4,500.
For higher-income taxpayers, the savings get even bigger. A taxpayer in the 37% bracket pays $37,000 on a $100,000 short-term gain versus $20,000 on the same gain if it is long-term. The difference is $17,000 — just for waiting past the one-year mark.
Our short-term vs long-term gains guide breaks down every bracket with exact numbers so you can see the savings for your specific income level. For a full picture of all the rates, check our capital gains tax rates breakdown.
2. Use Tax Loss Harvesting to Offset Gains
Tax loss harvesting means intentionally selling investments that have lost value to create deductible losses. Those losses then offset your capital gains, dollar for dollar.
Here is how it works in practice. You have $30,000 in capital gains from selling winning stocks this year. You also own three stocks that are down a total of $30,000 from what you paid. If you sell those losers, the $30,000 loss cancels out the $30,000 gain. Your net capital gain becomes zero. You owe zero capital gains tax.
Even if your losses exceed your gains, you still benefit. Up to $3,000 of net capital loss can be deducted against ordinary income like your salary. At a 24% marginal rate, that saves you $720 in federal tax. The remaining losses carry forward indefinitely, ready to offset gains in future years.
The key is doing this before December 31 each year. The trade must settle within the calendar year. Start reviewing your portfolio in November so you have time to identify candidates and execute trades without rushing.
Our tax loss harvesting complete guide walks through the full strategy with step-by-step examples and replacement investment ideas.
3. Avoid the Wash Sale Trap
The wash sale rule is the biggest trap in tax loss harvesting. If you sell a stock at a loss and buy the same stock — or a "substantially identical" one — within 30 days before or after the sale, the IRS disallows your loss.
That 30-day window runs both directions. The full restricted period is 61 days: 30 days before the sale, the sale date itself, and 30 days after. If you buy the same security anywhere in that window, your harvested loss gets added to the basis of your new shares instead of being deductible this year. You lose the current-year tax benefit — which was the whole point of selling.
What counts as substantially identical? Same company, different share class — yes, that triggers it. Same company on a different exchange — also yes. An S&P 500 ETF from Vanguard versus one from iShares — no, different providers tracking the same index are not substantially identical. This distinction is what makes index fund harvesting so practical.
Here is a real example. You sell 100 shares of Apple at a $5,000 loss on October 15. On October 20, you buy 100 shares of Apple back. The $5,000 loss is disallowed. It gets added to your new Apple shares' cost basis, and you cannot deduct it until you sell those replacement shares. You went through the trouble of harvesting but got zero benefit this year.
The fix is simple: replace harvested positions with something different enough to avoid the rule. Sell Vanguard Total Stock Market ETF (VTI) and buy iShares Core S&P Total US Stock Market (ITOT) instead. Same market exposure. No wash sale. Our wash sale rule explained covers every nuance with specific replacement suggestions for popular investments.
4. Sell in a Low-Income Year
Your capital gains tax rate depends on your total taxable income, not just the gain itself. This means the same gain can be taxed at very different rates depending on what else is happening in your finances that year.
A single filer with $40,000 of salary and a $50,000 long-term gain has total taxable income of $90,000. The first portion of that income falls into the 0% bracket, and the rest hits 15%. The actual tax on the $50,000 gain is roughly $6,250.
But what if that same person has $200,000 of salary and a $50,000 gain? Now total income is $250,000. The entire gain falls into the 20% bracket, and the 3.8% net investment income tax kicks in too. The tax on that same $50,000 gain jumps to roughly $11,900. Same gain. Nearly double the tax.
This is why timing matters so much. If you are planning to sell a big position, look at your income trajectory. Are you retiring next year and dropping to a much lower bracket? Taking a sabbatical? Going back to school? Any year where your ordinary income drops is a prime year to realize capital gains.
A client named Teresa deferred selling her business shares for two years until she retired. Her salary went from $180,000 to zero. She sold the shares for a $200,000 gain. Instead of paying roughly $47,600 in federal tax (20% plus 3.8% NIIT), she paid roughly $30,000 (15% with no NIIT). Waiting two years saved her $17,600.
Our how to calculate capital gains guide shows exactly how income and gains stack together to determine your rate.
5. Use the 0% Bracket Strategically
The 0% long-term capital gains bracket is one of the most underused provisions in the tax code. If your total taxable income falls below roughly $48,350 for single filers or $96,700 for married couples filing jointly, your long-term gains are taxed at zero percent. Not 15%. Not reduced. Actually zero.
This creates a genuine opportunity for people in certain situations. Retirees living on Social Security and modest savings often have taxable income well below these thresholds. If you are in this position, you can sell long-term investments and pay absolutely no federal capital gains tax on the proceeds.
But even higher-income households can use this bracket through careful planning. A married couple with $80,000 of taxable ordinary income has room for about $16,700 of long-term gains before crossing the 0% threshold. If they have gains sitting in their portfolio, they can realize up to $16,700 each year at a 0% federal rate. Do that for five years and they have moved $83,500 out of their portfolio with zero federal capital gains tax.
This strategy works especially well in years when income is temporarily low. A gap year between jobs, a year with large deductions, or the first year of retirement when salary drops off are all prime times to harvest gains at 0%.
6. Take Advantage of the Section 121 Home Exclusion
If you sell your primary residence, Section 121 lets you exclude up to $250,000 of gain if you are single, or $500,000 if you are married filing jointly. This exclusion wipes out the gain entirely — you never pay tax on it.
The rules are straightforward. You must have owned the home for at least two years and lived in it as your primary residence for at least two of the five years immediately before the sale. The two-year ownership and occupancy periods do not have to be continuous — they just need to total two years within that five-year window.
Let me run the numbers. You bought a house for $300,000 and sold it for $700,000 after living there for ten years. Your gain is $400,000. If you are married, the $500,000 exclusion covers the entire gain. You pay zero capital gains tax. If you are single, the $250,000 exclusion covers half the gain, and you pay tax on the remaining $150,000 at long-term rates.
You can use this exclusion once every two years. That means a couple who moves frequently could exclude $500,000 of gain on each home they sell, as long as they live in each one for at least two years.
There is also a partial exclusion if you have to sell before meeting the two-year requirement because of a job change, health issue, or other unforeseen circumstance. The partial exclusion prorates the full amount based on how long you actually lived there.
Our selling your home tax rules guide covers the Section 121 exclusion in full detail, including the partial exclusion rules and common pitfalls.
7. Consider a 1031 Exchange for Real Estate
A 1031 exchange lets you sell an investment property and buy another one without paying capital gains tax on the sale. The gain gets deferred — carried forward into the new property's basis — until you eventually sell that property without doing another exchange.
This strategy is available for real estate investors only. You cannot use it for stocks, crypto, or other assets. The properties must be "like-kind," which in practice means any real estate held for business or investment purposes qualifies — you can exchange a rental condo for a commercial warehouse, a vacant lot for an apartment building, or any other combination of investment real estate.
The rules are strict and the deadlines are unforgiving. You must identify up to three potential replacement properties within 45 days of selling your old property. You must close on at least one of those replacements within 180 days. Every dollar of gain that is not reinvested in the new property — called "boot" — gets taxed immediately.
Here is what the numbers look like. You sell a rental property for a $200,000 gain. Without a 1031 exchange, you would owe roughly $30,000 in federal capital gains tax at the 15% rate, plus any state tax and possibly the 3.8% NIIT. With a 1031 exchange, that $200,000 gain rolls into the basis of your new property and you owe zero tax this year. The gain remains deferred until you sell the replacement property.
Some investors chain multiple 1031 exchanges over decades, deferring gains again and again. When the final property is eventually sold, the accumulated deferred gain plus any depreciation recapture gets taxed. But by then, the investor may have died, and their heirs receive the property with a stepped-up basis that wipes out the deferred gain entirely.
Our 1031 exchange rules guide covers every requirement, deadline, and variation of this strategy.
8. Invest in Opportunity Zones for Deferral
Opportunity Zones were created by the Tax Cuts and Jobs Act to encourage investment in designated low-income areas. If you invest capital gains into a Qualified Opportunity Fund within 180 days of realizing those gains, you can defer the tax on those gains until you sell the Opportunity Fund investment or until December 31, 2026, whichever comes first.
The deferral works like this. You sell stock for a $100,000 long-term gain in March. Within 180 days, you invest that $100,000 into a Qualified Opportunity Fund. The $100,000 gain does not appear on your tax return this year. It gets deferred, reducing your current tax bill by roughly $15,000 at the 15% rate.
There is an additional benefit for long-held investments. If you hold the Opportunity Fund investment for at least ten years, any gain on the fund investment itself — not the original deferred gain, but the new appreciation — is excluded from tax entirely. This ten-year hold can eliminate tax on substantial growth.
The trade-off is risk. Opportunity Zones are in economically distressed areas by definition. The real estate or businesses you invest in may or may not succeed. You are trading tax benefits for investment risk, so evaluate the underlying asset on its merits first and treat the tax savings as a bonus.
9. Use Installment Sales to Spread Gains
An installment sale means you sell an asset but receive the payments over multiple years instead of all at once. Each year, you report only the portion of the gain that corresponds to the payment you received that year. This spreads the gain across several tax returns, potentially keeping you in a lower bracket each year.
This works best for real estate and other large assets. Say you sell a commercial property for a $300,000 gain. If you receive the full price in one year, that $300,000 gets added to your current income and could push you into the 20% bracket plus trigger the 3.8% NIIT. Your federal tax could exceed $69,000.
But if you structure the sale as a five-year installment with $60,000 of gain recognized each year, your income stays lower in each individual year. Instead of a single year with $300,000 of extra income, you have five years with $60,000 each. If your other income is moderate, each year's gain might stay in the 15% bracket and avoid the NIIT. Your total tax over five years could be roughly $45,000 instead of $69,000 — a savings of $24,000 just from spreading the gain.
The buyer pays you over time, usually with interest on the unpaid balance. That interest is ordinary income, taxed at your regular rate. So the capital gain portion gets the preferential treatment, while the interest portion does not. Still, the bracket management savings usually outweigh the interest income tax.
Installment sales are not available for stocks traded on an established market — you cannot sell Apple stock on an installment plan. They work for real estate, privately held business interests, and other assets that are not publicly traded.
10. Donate Appreciated Assets to Charity
When you donate an appreciated asset — like stock — directly to a qualified charity, you get two tax benefits at once. You avoid paying capital gains tax on the appreciation, and you get a charitable deduction for the full fair market value of the asset.
This is significantly better than selling the stock first and then donating cash. Here is why.
You own stock with a $20,000 cost basis and a current value of $50,000. If you sell the stock, you recognize a $30,000 long-term gain and pay roughly $4,500 in capital gains tax at the 15% rate. You then donate the remaining $45,500 in cash. Your charitable deduction is $45,500.
But if you donate the stock directly, you skip the sale entirely. No $30,000 gain gets recognized. No $4,500 tax gets paid. Your charitable deduction is the full $50,000 fair market value. You save $4,500 in capital gains tax and get a $4,500 larger deduction.
The savings multiply for larger donations. A $200,000 stock donation with a $50,000 basis avoids roughly $22,500 in capital gains tax at the 15% rate and gives you a $200,000 deduction instead of a $177,500 deduction after selling.
You must donate to a qualified public charity — not a private foundation, unless the foundation sells the stock immediately. And you must have held the stock for more than one year. Short-term gains do not get the same treatment; the deduction is limited to your cost basis.
11. Use a Donor-Advised Fund for Bunching
A donor-advised fund (DAF) is a charitable account you open with a sponsoring organization. You contribute assets to the DAF and take the full charitable deduction in the year you contribute. Then you recommend grants to specific charities from the DAF over time, on whatever schedule you want.
This solves a common problem. Many taxpayers alternate between years where their deductions exceed the standard deduction and years where they fall short. If your itemized deductions are $18,000 and the standard deduction is $15,700 for a single filer, you itemize and get a $2,300 benefit. But if your deductions drop to $12,000 next year, you take the standard deduction and your charitable giving produces zero additional tax benefit.
A DAF lets you bunch multiple years of charitable giving into one tax year. You contribute several years' worth of appreciated stock to the DAF in a high-income year, take the full deduction that year, and then distribute grants to your favorite charities over the next several years.
The strategy combines with Strategy 10 beautifully. You donate appreciated stock to the DAF, avoiding capital gains tax and getting a full fair market value deduction. Then you grant the money out gradually. You get the tax benefit concentrated in the year when your income is highest and your deduction is most valuable, while your charitable giving stays steady across multiple years.
12. Maximize Retirement Contributions to Lower AGI
Your capital gains tax rate depends on your adjusted gross income. Every dollar you can reduce your AGI pushes you closer to — or keeps you in — a lower capital gains bracket. Retirement contributions are one of the most direct ways to do this.
For 2026, the 401(k) contribution limit is $23,500 for employees. If you are over 50, you can add another $7,500 as a catch-up contribution, bringing your total to $31,000. If you are between 60 and 63, the enhanced catch-up allows up to $11,250 extra, for a maximum of $34,750. Every dollar you contribute reduces your AGI by that same dollar.
IRA contributions reduce AGI too. The 2026 limit is $7,000 for traditional IRAs, with a $1,000 catch-up for those 50 and older. If you qualify for a deduction — which depends on your income and whether you have a workplace plan — that $7,000 comes straight off your AGI.
Here is what this can do for your capital gains tax. A single filer with $95,000 in salary and a $50,000 long-term gain has total income that falls in the 15% long-term bracket. The tax on the gain is $7,500. But if this person contributes $23,500 to a 401(k), their AGI drops to $71,500 plus the $50,000 gain, totaling $121,500. They stay in the 15% bracket and still pay $7,500 on the gain — but they also saved $5,170 in ordinary income tax on their salary at the 22% rate.
The real win comes when AGI reductions push you across a bracket threshold. A married couple with $250,000 of income (including gains) is in the 20% bracket and pays the 3.8% NIIT. If they contribute $47,000 to two 401(k)s, their income drops to $203,000. They may drop below the NIIT threshold and fall into the 15% bracket. The savings on a $50,000 gain would be roughly $9,500 — plus the ordinary income tax savings from the 401(k) contributions themselves.
Our net investment income tax guide explains the NIIT thresholds and how AGI reductions can eliminate this 3.8% surtax.
Putting These Strategies Together
The real power comes from combining multiple strategies. A client named Michael retired in 2026 with a $160,000 salary that dropped to zero. He had $200,000 of long-term stock gains to realize. He also had $35,000 of unrealized losses in his portfolio. Here is what we did.
First, he harvested the $35,000 in losses to offset part of the $200,000 in gains. His net gain dropped to $165,000. Second, with zero salary that year, his total taxable income fell into the 15% bracket instead of the 20% bracket he would have hit with his full salary. Third, he contributed $7,000 to a traditional IRA from his other savings, further reducing his AGI. Fourth, he donated $15,000 of the appreciated stock directly to charity, avoiding capital gains tax on that portion entirely.
His final taxable gain was $115,000 after the loss offset and charitable donation. At the 15% rate with no NIIT, his total federal capital gains tax was roughly $17,250. Without any strategies, the same $200,000 gain on his previous salary would have been taxed at 20% plus 3.8%, resulting in roughly $47,600. He saved over $30,000 by using four strategies together.
For state-level planning, check our state capital gains rates compared guide. Moving to or establishing residency in a lower-tax state before realizing large gains can add thousands more in savings on top of the federal strategies.
These twelve strategies are not secrets. They are provisions built into the Internal Revenue Code, available to every taxpayer who meets the requirements. The key is knowing which ones apply to your situation and executing them correctly. Use our capital gains tax calculator to estimate your current tax, then work through these strategies one by one to see how much you can reduce it.
Fact-Checked & Reviewed
This article was written by James Park (EA, CFP (Certified Financial Planner)) and reviewed for accuracy by David Chen (JD, LLM in Taxation (New York University)). All tax rates, thresholds, and rules referenced are based on IRS publications and current tax law as of the date published. Tax laws change frequently — always consult a qualified tax professional for advice specific to your situation.
Disclaimer: This article is for informational purposes only and does not constitute tax, legal, or financial advice. Tax laws and regulations change frequently, and the information presented here may not reflect the most current updates. You should consult with a qualified CPA, tax attorney, or financial advisor before making any tax-related decisions. TaxGainsCalc is not responsible for any actions taken based on the information provided in this article.