How to avoid capital gains tax on stocks — 7 legal strategies
You cannot dodge tax you genuinely owe, but the tax code hands ordinary investors a whole toolkit for paying less — or nothing — on stock profits. Here are seven legal, IRS-sanctioned moves: holding past a year, harvesting losses, using Roth and retirement accounts, the 0% bracket, gifting shares, and the step-up at death.
⚑ Educational information, not tax or legal advice
This is general educational content, not legal, tax or investment advice and not a substitute for a professional. These are legal tax-planning strategies, never evasion — and the rules, thresholds and rates change. Results vary by your state, filing status and individual case. Before acting, consult a licensed CPA, enrolled agent or tax attorney about your own situation.
When you sell a stock for more than you paid, the profit is a capital gain, and the IRS taxes part of it. The good news: the tax code is full of legitimate ways to shrink that bill. None of what follows is a loophole or a scheme — these are mainstream tax-planning moves that financial advisors use every day. The line is simple. Tax avoidance — arranging your affairs to legally pay less — is allowed and expected. Tax evasion — hiding income or lying on a return — is a crime. Everything below sits firmly on the legal side.
First, the rule that does most of the work
Before any clever strategy, understand the single biggest lever: your holding period. The tax code splits stock profits into two buckets based purely on how long you owned the shares.
- Short-term gain — held one year or less. Taxed at your ordinary income rate, the same brackets as your wages (10% to 37%).
- Long-term gain — held more than one year. Taxed at the preferential 0%, 15% or 20% long-term rates.
That gap is enormous. A high earner selling after eleven months can pay nearly double what they would have paid by simply waiting past the one-year mark. The clock starts the day after you buy, so "a year and a day" is the threshold. If you are close and don't urgently need the cash, waiting is often the highest-return decision you can make all year. For the full bracket breakdown, see our guide to how capital gains tax works.
The seven strategies at a glance
Here is the whole toolkit in one view, with who each move suits best. We unpack each one below.
| Strategy | What it does | Best for |
|---|---|---|
| Hold > 1 year | Drops rate from ordinary (up to 37%) to 0/15/20% | Almost everyone |
| Tax-loss harvesting | Losses offset gains dollar-for-dollar; $3k vs income | Taxable brokerage holders |
| Roth IRA / 401(k) | No capital gains tax on sales inside the account | Long-term retirement savers |
| Traditional IRA / 401(k) | Defers all tax until withdrawal | High earners now, lower later |
| Sell in the 0% bracket | Realize long-term gains at a 0% rate | Low-income / gap years |
| Donate appreciated shares | Skip the gain entirely, deduct full value | Charitable givers who itemize |
| Step-up in basis at death | Heirs inherit at current value, gain erased | Estate & legacy planning |
1. Hold for more than a year
The simplest and most powerful move. Crossing from short-term to long-term can roughly halve your rate with zero cost beyond patience. If you bought eleven months ago and the thesis still holds, waiting four extra weeks can be worth thousands. The only caveat is risk: a stock can fall in those weeks, so weigh the tax saving against the chance the price moves against you.
2. Harvest losses to offset gains
If some positions are underwater, selling them realizes a capital loss that offsets your gains dollar-for-dollar. Sell a loser, bank the loss, and it cancels out an equal amount of gain. If your net losses exceed your gains, you can deduct up to $3,000 against ordinary income each year, and carry the remainder forward indefinitely to future tax years.
One rule to respect: the wash-sale rule. If you buy the same — or a "substantially identical" — security within 30 days before or after the sale, the IRS disallows the loss. The usual fix is to buy a similar-but-not-identical fund (for example a different broad-market index ETF) so you stay invested while still booking the loss.
3. Use tax-advantaged accounts
Gains realized inside a retirement account are not taxed when you sell within the account, which makes these the cleanest way to trade without a tax drag.
Roth IRA and Roth 401(k)
You contribute after-tax dollars, but everything afterward — growth, dividends, and stock sales — is tax-free, and qualified withdrawals in retirement are tax-free too. Capital gains tax never enters the picture. This is the gold standard for younger investors with decades of compounding ahead.
Traditional IRA and 401(k)
Contributions are pre-tax, so you defer all tax until you withdraw in retirement — when the money is taxed as ordinary income, not at capital gains rates. The trade is "tax-free forever" (Roth) versus "tax-deferred and a deduction now" (traditional). If you are weighing the two, our Roth vs traditional IRA calculator compares the long-run after-tax outcome for your numbers.
4. Harvest gains inside the 0% bracket
Long-term rates step down with income, and the bottom rung is literally 0%. In a year when your taxable income is low — a sabbatical, a career break, a gap between jobs, or early retirement before pensions begin — you can deliberately sell appreciated stock and pay no federal tax on the long-term gain, up to the top of the 0% band.
Some investors then immediately rebuy the same shares. Because there is no wash-sale rule on gains (only losses), this resets your cost basis higher, quietly erasing future taxable gain. Mind the edge: realized gains count as income, so stacking too much can push you out of the 0% band and into 15%.
→ See exactly how much each strategy saves you
Enter your purchase price, sale price, holding period and income to compare short-term vs long-term tax side by side — and see how harvesting a loss or waiting past the one-year mark changes the bill.
5. Donate appreciated shares to charity
If you give to charity anyway, donating stock instead of cash is one of the most tax-efficient moves available. When you donate shares you have held more than a year directly to a qualified charity or a donor-advised fund, two things happen: you avoid the capital gains tax entirely on the appreciation, and you can deduct the full fair-market value if you itemize. Selling the stock first, paying the gains tax, then donating the cash leaves you with less to give and a smaller deduction.
6. Use the step-up in basis at death
This one is for legacy planning. When you die, the assets your heirs inherit usually get a stepped-up cost basis — reset to the market value on the date of death. Decades of unrealized gain can simply vanish. A stock you bought at $10,000 that is worth $200,000 would carry a $190,000 taxable gain if you sold it; if instead your heir inherits it at the stepped-up $200,000 basis and sells, the taxable gain is roughly zero. For highly appreciated shares you don't need to spend, holding rather than selling can be the most tax-efficient choice of all.
7. Net gains against losses across your whole portfolio
Finally, remember that the IRS taxes your net capital gain. At year-end, gains and losses across all your holdings are netted together. A profitable sale in one stock can be wiped out by a loss in another. Reviewing the full picture before December — not just one trade in isolation — is how you make sure you are taxed only on your true net profit, and how you decide whether to realize a loss to balance a gain before the year closes.
A quick worked example
Say you have a $6,000 long-term gain on one stock and a $4,000 loss sitting in another. Sell both and you net to a $2,000 taxable gain. Hold both and you owe tax on the full $6,000. The table shows the difference for a 15% filer.
| Approach | Taxable gain | Tax at 15% |
|---|---|---|
| Sell winner only | $6,000 | $900 |
| Sell winner + harvest the loss | $2,000 | $300 |
| Winner held > 1 year, sold in 0% year | $6,000 | $0 |
Illustrative only — ignores state tax and the 3.8% net investment income tax. Your actual result depends on total income, filing status and current brackets.
Where the legal line is
Every strategy here is built into the tax code on purpose. Holding longer, harvesting losses, using retirement accounts, gifting shares — the IRS publishes the rules and expects you to use them. What crosses the line is hiding sales, faking a loss, or claiming a wash-sale loss you aren't entitled to. The dividing principle is honesty: report everything accurately and arrange your timing legally. When in doubt, a CPA earns their fee many times over on a single well-timed sale.
Frequently asked questions
Can you legally avoid capital gains tax on stocks?
Yes. You can't evade tax you owe, but you can legally reduce or eliminate it: hold over a year, harvest losses, invest inside Roth or retirement accounts, sell in the 0% bracket, and donate appreciated shares. These are planning, not evasion — confirm the specifics with a CPA.
How long do I have to hold a stock to avoid the higher tax rate?
More than one year. One year or less is a short-term gain taxed at your ordinary rate (up to 37%). A year and a day makes it long-term, taxed at 0/15/20%. The clock starts the day after you buy.
What is tax-loss harvesting and how much can it save?
Selling losing positions to realize losses that offset gains dollar-for-dollar. Net losses can offset up to $3,000 of ordinary income a year, with the rest carried forward. Avoid the wash-sale rule by not rebuying the same security within 30 days.
Do I pay capital gains tax on stocks sold inside a Roth IRA or 401(k)?
No. Sales inside a Roth IRA, traditional IRA or 401(k) trigger no capital gains tax. A Roth is tax-free in retirement; a traditional account defers tax until withdrawal, when it's taxed as ordinary income.
Does donating appreciated stock avoid capital gains tax?
Yes. Donate shares held over a year directly to a qualified charity and you skip the capital gains tax on the appreciation, plus you can deduct the full fair-market value if you itemize — more efficient than selling and donating cash.
→ Try the calculator before your next sale
The fastest way to see which of these strategies moves your bill the most is to run your own numbers.
Sources & further reading
- IRS — Topic No. 409, Capital Gains and Losses, and Publication 550 (Investment Income and Expenses), irs.gov.
- IRS — Topic No. 409 wash sales, Publication 551 (Basis of Assets) on stepped-up basis, and Publication 526 (Charitable Contributions).
- IRS — Roth IRA and 401(k) rules in Publication 590-A/590-B and Publication 560; annual inflation-adjusted long-term capital gains thresholds.
Last updated: 19 June 2026. Read our full disclaimer →