You cannot avoid capital gains tax entirely, but you can reduce what you owe through timing, account type, and donation strategies
Capital gains tax is owed when you sell a stock for more than you paid for it. The tax rate depends on how long you held the stock and your income level. You cannot eliminate this tax, but the IRS allows several legal methods to reduce it: holding stocks longer to may have access to for lower rates, using tax-advantaged accounts, offsetting gains with losses, and donating appreciated shares to charity instead of selling them.
The strategy that works best depends on your situation — whether you have losses to offset gains, whether you can afford to hold stocks longer, and whether you have room in retirement accounts. This guide covers the main approaches people use.
Key Takeaways
- Holding a stock for more than one year before selling qualifies you for long-term capital gains rates, which are lower than short-term rates for most income levels.
- Stocks held inside a 401(k), traditional IRA, or Roth IRA generate no capital gains tax when you sell them, though withdrawal rules and income limits apply to each account type.
- You can offset capital gains by selling stocks at a loss in the same year, a strategy called tax-loss harvesting.
- Donating appreciated stock directly to a charity avoids the capital gains tax entirely and gives you a charitable deduction for the full current value.
- The IRS tracks your cost basis — the price you paid — so keep purchase records and confirm your broker's records match before you sell.
Hold stocks for over one year to pay the lower long-term rate
The IRS taxes capital gains at two different rates: short-term and long-term. A short-term capital gain is profit on a stock you held for one year or less. It is taxed as ordinary income at your regular tax bracket — potentially 10%, 12%, 22%, 24%, 32%, 35%, or 37% depending on your total income.
A long-term capital gain is profit on a stock you held for more than one year. The tax rate is 0%, 15%, or 20% depending on your income level. For 2024, the 0% rate applies to single filers earning under $47,025 and married filers earning under $94,050. The 15% rate applies to most middle-income earners. The 20% rate applies to high earners. These income thresholds change each year.
The holding period starts the day after you buy the stock and ends the day you sell it. If you bought on January 15 and sold on January 16 of the next year, you may have access to for long-term treatment. If you sell on January 15 of the next year, you do not.
This is the simplest strategy: if you can wait, waiting reduces your tax bill. If you have a stock that has gained $5,000 and you are in the 24% tax bracket, selling now costs you $1,200 in tax. Holding one more month and may have access to for the 15% long-term rate costs you $750 — a $450 difference.
Use tax-advantaged retirement accounts to avoid capital gains tax entirely
Stocks held inside a 401(k), traditional IRA, or Roth IRA do not trigger capital gains tax when you sell them, even if you sell at a profit the day after you buy. You can buy and sell stocks inside these accounts without any tax consequence until you withdraw the money.
A traditional 401(k) or traditional IRA defers the tax: you do not pay capital gains tax on the sale, but you pay ordinary income tax on the entire withdrawal amount when you take money out in retirement. A Roth IRA or Roth 401(k) avoids the tax entirely: you pay no tax on withdrawals in retirement, including all the gains.
The catch is contribution limits. For 2024, you can contribute $7,000 per year to an IRA (or $8,000 if you are 50 or older). A 401(k) allows $23,500 per year (or $31,000 if you are 50 or older), but only if your employer offers one and you are employed. A Roth IRA has income limits: if you earn over $161,000 as a single filer or $240,000 as a married filer filing jointly in 2024, you cannot contribute directly.
If you have already maxed out these accounts, you cannot use them to shelter additional stock gains. If you have not, moving future stock purchases into a retirement account is the most powerful tax reduction available.
Offset gains by selling stocks at a loss in the same tax year
Tax-loss harvesting means selling a stock at a loss to offset a gain you made on another stock. If you sold Stock A for a $3,000 gain and Stock B for a $2,000 loss in the same year, your net gain is $1,000, and you owe tax only on that $1,000.
You can also use losses to offset gains from previous years. If you have a $5,000 loss this year and no gains, you can deduct up to $3,000 of the loss against your ordinary income, reducing your taxable income. The remaining $2,000 carries forward to next year.
The IRS has one rule: the wash-sale rule. If you sell a stock at a loss, you cannot buy the same stock (or a substantially identical one) within 30 days before or after the sale. If you do, the loss is disallowed and added back to your cost basis. You can buy a similar stock in the same sector — for example, if you sell a tech stock at a loss, you can buy a different tech stock immediately — but not the same one.
This strategy works best if you have both winners and losers in your portfolio. If all your stocks are up, there is nothing to harvest. If all are down, you can harvest losses but have no gains to offset.
Donate appreciated stock directly to charity instead of selling
If you own a stock that has gained significantly and you want to give money to charity, donating the stock itself is more tax-efficient than selling it and donating the cash.
When you donate appreciated stock directly to a may have access to charity, two things happen: you avoid the capital gains tax on the appreciation, and you receive a charitable deduction for the full current market value of the stock. If you bought a stock for $2,000 and it is now worth $10,000, donating it means you deduct $10,000 from your taxable income and owe zero capital gains tax on the $8,000 gain.
If you sold the stock first, you would owe capital gains tax on the $8,000 gain (at least $1,200 at the 15% long-term rate), leaving you with less than $10,000 to donate. The charity receives the same amount either way, but your tax bill is lower if you donate the stock.
The charity must be a may have access to organization — the IRS website has a searchable database. You cannot donate to a donor-advised fund and claim the deduction; you must donate directly to the charity. You will need a written appraisal of the stock's value for your tax records if the donation is over $5,000.
Track your cost basis and use specific identification when you sell
Your cost basis is the original price you paid for a stock plus any fees. The capital gain is the sale price minus the cost basis. The IRS requires you to keep records of what you paid.
If you bought the same stock multiple times at different prices, you can choose which shares to sell. This is called specific identification. If you bought 100 shares at $10, then 100 shares at $20, and the stock is now worth $30, you can choose to sell the shares you bought at $20 (a $10 gain per share) instead of the ones at $10 (a $20 gain per share). This reduces your taxable gain.
Your broker tracks cost basis automatically, but you should confirm their records match your own before you sell. Brokers sometimes make errors, especially if you transferred shares from another broker or inherited stock. If the broker's records are wrong, you are responsible for correcting them on your tax return.
When you place a sell order, tell your broker you want to use specific identification and specify which lot (purchase batch) to sell. If you do not specify, the IRS assumes you sold shares in the order you bought them — usually the worst option for taxes.
Understand the net investment income tax for high earners
If your income is above a certain threshold, you may owe an additional 3.8% tax on capital gains. This is called the net investment income tax and applies to single filers earning over $200,000 and married filers earning over $250,000.
The tax is 3.8% of your net investment income — which includes capital gains, dividends, and interest — or the amount your income exceeds the threshold, whichever is less. If you are a single filer earning $210,000 and have $5,000 in capital gains, you owe 3.8% on the $5,000, which is $190.
This tax applies whether you hold the stock long-term or short-term. It is separate from the capital gains tax itself. If you are in the 20% long-term capital gains bracket and subject to the net investment income tax, your total tax on a capital gain is 23.8%.
Frequently Asked Questions
Can I avoid capital gains tax by holding a stock forever?
No. You owe capital gains tax when you sell, not when you hold. If you never sell, you never owe the tax — but you also never access the profit. When you die, your heirs receive a "stepped-up basis," meaning they inherit the stock at its value on the date of death, and they owe no tax on gains that occurred during your lifetime. This is a benefit of holding, not a tax avoidance strategy.
What if I sell a stock at a loss — can I deduct the full loss?
No. You can deduct capital losses against capital gains dollar-for-dollar. If you have no gains, you can deduct up to $3,000 of losses against ordinary income in a single year. Any loss beyond that carries forward to future years. You cannot deduct a loss as a direct expense on your tax return.
Do I owe capital gains tax on stocks inside a 529 college savings plan?
No. Like retirement accounts, 529 plans do not trigger capital gains tax when you sell stocks inside the account. You pay tax only when you withdraw the money for college expenses. Non-may have access to withdrawals are taxed as ordinary income plus a 10% penalty on the earnings portion.
If I inherit stock, do I owe capital gains tax on the gain before I inherited it?
No. You inherit the stock at its market value on the date of the person's death. That becomes your cost basis. You owe capital gains tax only on gains that occur after you inherit it. This is called a stepped-up basis and is one of the largest tax benefits in the U.S. tax code.
Can I reduce capital gains tax by timing my sale across two calendar years?
No. The IRS uses the tax year, not the calendar year, to measure holding periods and calculate gains. If you sell in December and buy again in January, that is still the same tax year for purposes of short-term versus long-term treatment. However, you can use year-end sales to harvest losses before December 31 and offset gains from earlier in the year.