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 applies to the profit, not the full sale price. You cannot eliminate this tax, but the amount you pay depends on how long you held the stock, which account it sits in, and what you do with the proceeds. A stock held for more than one year gets taxed at a lower rate than one held for less than a year. Money in a 401(k) or Roth IRA never triggers capital gains tax at all — the tax treatment happens at withdrawal, not at sale. Stocks donated to charity avoid capital gains tax entirely on the appreciation. These are the main levers available to you.
Key Takeaways
- Long-term capital gains (stocks held over one year) are taxed at 0%, 15%, or 20% depending on your income; short-term gains are taxed as ordinary income, which is higher for most people.
- Stocks held inside a 401(k), traditional IRA, or Roth IRA do not trigger capital gains tax when you sell them — you only pay tax (or nothing) when you withdraw the money.
- Donating appreciated stock to a registered charity lets you deduct the full current value and avoid capital gains tax on the appreciation.
- Selling at a loss can offset gains from other sales in the same year, and unused losses can carry forward to future years.
- The year you sell matters: bunching gains into years when your income is lower results in a lower tax rate on those gains.
How holding period changes your tax rate
The length of time you own a stock before selling it determines which tax rate applies to your profit. If you sell a stock you have owned for one year or less, the profit is a short-term capital gain and is taxed as ordinary income — the same rate as your salary or wages. If you sell a stock you have owned for more than one year, the profit is a long-term capital gain and is taxed at a preferential rate: 0%, 15%, or 20%, depending on your total income for the year.
For most people, the long-term rate is substantially lower. A person in the 24% federal income tax bracket pays 15% on long-term gains instead. Someone in the 37% bracket pays 20%. The 0% rate applies to long-term gains for people whose total income falls below a certain threshold — $47,025 for single filers and $94,050 for married filing jointly in 2024, though these numbers change yearly.
The holding period is measured from the date you buy to the date you sell. If you buy on June 15 and sell on June 16 of the following year, it counts as long-term. If you sell on June 14, it is short-term. This means delaying a sale by a few days or weeks can sometimes move you from short-term to long-term treatment and lower your tax bill significantly.
Keeping stocks in tax-deferred and tax-free accounts
Stocks held inside a 401(k), 403(b), or traditional IRA never generate capital gains tax when you sell them, no matter how long you held them or how much profit you made. You can buy and sell stocks within these accounts as often as you want without triggering any tax. The tax is deferred until you withdraw money from the account in retirement.
A Roth IRA goes further: stocks held inside a Roth IRA are never taxed on their gains, even at withdrawal, as long as you follow the withdrawal rules (generally, you must be 59½ and have held the account for at least five years). This makes a Roth IRA the most tax-efficient place to hold stocks you plan to trade or that you expect to appreciate significantly.
The trade-off is contribution limits. In 2024, you can contribute $7,000 per year to a traditional or Roth IRA (or $8,000 if you are 50 or older), and $23,500 to a 401(k) (or $31,000 if 50 or older). These limits reset each January. If you have more money to invest than these limits allow, the excess must go into a regular taxable brokerage account, where capital gains tax will explore when you sell.
Donating appreciated stock to charity
If you own stock that has increased in value and you want to donate to charity, you can donate the stock itself rather than selling it and donating the cash. When you do this, you avoid capital gains tax on the appreciation entirely, and you get a tax deduction for the full current market value of the stock.
Example: You bought 100 shares of a stock for $1,000 total. It is now worth $5,000. If you sell it, you owe capital gains tax on the $4,000 profit. If you donate those 100 shares directly to a registered charity, you deduct $5,000 and owe zero capital gains tax. The charity receives $5,000 worth of stock, and you get the deduction. This works only if the charity is registered as a 501(c)(3) or similar tax-exempt organization, and you must itemize deductions on your tax return for the deduction to benefit you.
To donate stock, contact your brokerage and ask for the charity's Delivery Instruction Letter or DTC number. Your brokerage will transfer the shares directly to the charity's account. Do not sell the stock first — if you sell and then donate the proceeds, you trigger capital gains tax and lose the benefit.
Using losses to offset gains
If you sell a stock at a loss, you can use that loss to reduce capital gains from other stock sales in the same year. This is called tax-loss harvesting. If your losses exceed your gains in a year, you can deduct up to $3,000 of the net loss against your ordinary income. Any remaining loss carries forward to future years and can be used to offset gains or income in those years.
Example: In 2024, you sell Stock A for a $2,000 gain and Stock B for a $3,000 loss. Your net loss is $1,000. You can deduct $1,000 against your ordinary income. If you had no other gains or income to offset, you would deduct the full $1,000 and carry forward $0.
There is one restriction: 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 to the cost basis of the new purchase instead. This rule prevents you from selling a stock to claim a loss and when ready buying it back.
Timing income and gains across years
Your capital gains tax rate depends on your total income for the year. If you can arrange to realize gains in a year when your other income is lower, you may pay a lower rate on those gains or even may have access to for the 0% long-term rate.
This is most relevant if you are between jobs, taking a sabbatical, or retiring mid-year. If you know your income will be unusually low in a particular year, you might sell appreciated stocks that year rather than waiting. Conversely, if you expect a large bonus or a spike in self-employment income, you might delay stock sales to a different year.
The strategy works because long-term capital gains are taxed in "layers" — gains that fall within the 0% bracket are taxed at 0%, gains in the next layer are taxed at 15%, and so on. If your income is $50,000 and you have $20,000 in long-term gains, some or all of those gains may fall into the 0% bracket. If your income is $150,000, those same gains would be taxed at 15%.
Holding stocks until death
When you die, your heirs inherit stocks at their market value on the date of your death. This is called a step-up in basis. If you bought a stock for $10,000 and it is worth $50,000 when you die, your heirs inherit it with a basis of $50,000. If they sell it when ready, they owe no capital gains tax, even though the stock appreciated $40,000 while you owned it.
This is not a strategy you can control — it happens automatically. But it is worth understanding if you are deciding whether to sell appreciated stock now or hold it. Holding until death eliminates capital gains tax on the appreciation, though it may trigger estate tax if your total estate is large enough. Estate tax applies only to estates exceeding $13.61 million per person in 2024 (this threshold changes yearly), so most people do not face it.
Frequently Asked Questions
Can I avoid capital gains tax by holding a stock forever?
No. As long as you own the stock, you owe no tax. But the moment you sell it, capital gains tax is due on the profit. The only way to avoid the tax entirely is to donate the stock to charity, hold it in a tax-deferred account like a 401(k), or hold it until you die (in which case your heirs get the step-up in basis).
What is the difference between short-term and long-term capital gains tax?
Short-term gains (stocks held one year or less) are taxed as ordinary income, which ranges from 10% to 37% depending on your income bracket. Long-term gains (stocks held over one year) are taxed at 0%, 15%, or 20%. For most people, long-term rates are significantly lower. Waiting just a few weeks or months to cross the one-year threshold can save hundreds or thousands in taxes.
Do I have to pay capital gains tax if I reinvest the money?
Yes. Capital gains tax is owed when you sell, regardless of what you do with the proceeds. Whether you spend the money, reinvest it in other stocks, or put it in a savings account does not change the tax. The tax is based on the profit from the sale, not on how you use the money afterward.
Can I claim a capital loss if a stock goes to zero?
Yes. If a stock becomes worthless, you can claim a capital loss for the full amount you paid for it. You must actually sell the shares or formally abandon them (check with your tax preparer on the documentation required). You cannot straightforward declare them worthless without taking action. The loss can offset other gains or up to $3,000 of ordinary income in that year.
Does the capital gains rate change every year?
The tax rates themselves (0%, 15%, 20%) do not change, but the income thresholds that determine which rate applies do change yearly. The IRS adjusts these thresholds for inflation. In 2024, the 0% rate applies to long-term gains for single filers with income up to $47,025. In 2025, that threshold will be higher. Check the IRS website or a tax professional for the current year's thresholds.