How to Avoid Tax on Stock Gains: Holding, Accounts, and Losses

You can legally reduce or eliminate federal tax on stock gains by controlling when and how you sell: hold shares more than a year to qualify for long-term rates as low as 0%, keep growth inside retirement accounts or an HSA, offset gains with harvested losses, donate appreciated shares directly to charity, plan transfers through gifts or inheritance, and, for eligible startup shares, claim the Section 1202 exclusion. There is no way to avoid tax on stock gains without using one of these specific mechanisms; the rest of this article walks through each.

Hold Shares More Than One Year

The single largest lever most investors have is the calendar. Sell inside one year and the profit is taxed at ordinary income rates, which top out at 37%. Sell after holding more than a year and the same profit qualifies for long-term capital gains rates of 0%, 15%, or 20%.1Internal Revenue Service. Topic No. 409, Capital Gains and Losses

Which of the three long-term rates you pay depends on total taxable income. For 2026:

  • 0% applies to taxable income up to $49,450 (single), $98,900 (married filing jointly), or $66,200 (head of household).
  • 15% applies above those thresholds and below $545,500 (single), $613,700 (joint), or $579,600 (head of household).
  • 20% applies above the 15% ceiling.2Tax Foundation. 2026 Tax Brackets and Federal Income Tax Rates

Selling on day 364 versus day 366 can nearly double the tax rate on the same gain. If you don’t urgently need the cash, waiting past the one-year mark is the simplest move on this list.

The 3.8% Net Investment Income Tax

Higher earners face an extra 3.8% surtax on investment income, including capital gains, once modified adjusted gross income passes $200,000 (single) or $250,000 (joint). Those thresholds are not indexed for inflation.3Internal Revenue Service. Questions and Answers on the Net Investment Income Tax Stacked on the 20% long-term rate, the maximum federal rate on a stock gain reaches 23.8%. The surtax applies to the lesser of your net investment income or the amount by which your MAGI exceeds the threshold, so crossing the line by a small amount doesn’t drag your entire gain into the 3.8% bucket.4Internal Revenue Service. Topic No. 559, Net Investment Income Tax

Keep Stocks Inside Retirement or Health Accounts

Certain accounts let stocks grow and even be sold inside them without producing a taxable event that year. The trade-off is limited access to the money, generally until retirement.

Traditional IRAs and 401(k) Plans

Traditional IRA contributions are pre-tax or tax-deductible, and investments compound without annual tax. You owe ordinary income tax only when you take distributions.5Office of the Law Revision Counsel. 26 USC 408 – Individual Retirement Accounts A 401(k) works the same way through payroll deferral.6Office of the Law Revision Counsel. 26 USC 401 – Qualified Pension, Profit-Sharing, and Stock Bonus Plans For 2026, contribution limits are $7,500 for an IRA and $24,500 for a 401(k), with a $1,000 IRA catch-up and an $8,000 401(k) catch-up available at age 50.7Internal Revenue Service. 401(k) Limit Increases to $24,500 for 2026, IRA Limit Increases to $7,500

Roth IRAs

A Roth reverses the timing. Contributions are made with money you’ve already paid tax on, but qualified withdrawals of both contributions and gains come out tax-free.8Office of the Law Revision Counsel. 26 USC 408A – Roth IRAs Buy a stock at $10 inside a Roth, sell it at $500, and no federal tax is ever due on that gain. That structure suits your highest-growth holdings.

Direct Roth contributions phase out in 2026 between $153,000 and $168,000 of modified AGI for single filers and between $242,000 and $252,000 for joint filers.7Internal Revenue Service. 401(k) Limit Increases to $24,500 for 2026, IRA Limit Increases to $7,500 Above those ranges, backdoor Roth conversions remain available to many people.

Health Savings Accounts

An HSA gives three tax breaks on the same dollar: the contribution is deductible, growth is untaxed, and withdrawals for qualified medical expenses are tax-free.9Internal Revenue Service. Publication 969 (2025), Health Savings Accounts and Other Tax-Favored Health Plans Many HSAs let you invest the balance in stocks and funds, and those gains never face tax if used for medical costs. The 2026 contribution limits are $4,400 for self-only coverage and $8,750 for family coverage; you need a high-deductible health plan to be eligible.10Internal Revenue Service. Notice 26-05 – 2026 HSA Limits

Offset Gains With Harvested Losses

Not every holding wins. Losses can neutralize gains, and in some years you can even harvest gains at a 0% rate.

Tax-Loss Harvesting

Sell a losing position and the realized loss offsets realized gains for the same year. If losses exceed gains, up to $3,000 of the excess ($1,500 if married filing separately) can offset ordinary income, and any remainder carries forward indefinitely.1Internal Revenue Service. Topic No. 409, Capital Gains and Losses

The catch is the wash-sale rule. Buy back the same security, or one substantially identical, within 30 days before or after the sale, and the loss is disallowed for the current year. The disallowed amount is added to the basis of the replacement shares.11Office of the Law Revision Counsel. 26 USC 1091 – Loss From Wash Sales of Stock or Securities A common workaround is to move into a different fund or ETF that tracks a similar index without being considered substantially identical.

Harvesting Gains in the 0% Bracket

If your taxable income for the year falls below the 0% long-term threshold ($49,450 single, $98,900 joint for 2026), you can deliberately sell appreciated long-term shares and pay no federal tax on the gain.2Tax Foundation. 2026 Tax Brackets and Federal Income Tax Rates The wash-sale rule doesn’t apply to gains, so you can buy the same stock back immediately and reset your basis higher, shrinking the taxable gain on the eventual real sale. This is most useful in low-income years: a gap between jobs, a heavy-deduction year, or the early years of retirement before Social Security and required minimum distributions start. Run the numbers first, because the gain itself counts toward taxable income and can push you out of the 0% band.

Estimated Tax After a Large Gain

Cashing out a big position mid-year can trigger an underpayment penalty even if you pay in full at filing. To stay safe, total withholding and estimated payments generally need to cover at least 90% of the current year’s tax or 100% of last year’s (110% if prior-year AGI exceeded $150,000).12Internal Revenue Service. Underpayment of Estimated Tax by Individuals Penalty Consider a quarterly estimated payment in the quarter of the sale.

Donate Appreciated Shares to Charity

Transferring long-term appreciated stock directly to a qualified charity, instead of selling and donating cash, eliminates the capital gains tax on the appreciation. The charity receives full market value, and you can deduct that same value as a charitable contribution.13Internal Revenue Service. Publication 526 (2025), Charitable Contributions

The deduction for donated appreciated stock is capped at 30% of your adjusted gross income, with a five-year carryforward for any excess.14Internal Revenue Service. Charitable Contribution Deductions On $200,000 of AGI, an $80,000 stock gift produces a $60,000 deduction this year and $20,000 to carry forward.

A donor-advised fund works as an intermediary if you want the deduction now but haven’t chosen final recipients. You transfer the shares to the fund, claim the fair market value deduction, and recommend grants to specific charities over time. Stock gifts valued above $5,000 generally require a qualified appraisal, and you’ll need transfer documentation and a receipt from the recipient organization.

Plan Transfers Through Gifts or Inheritance

Lifetime gifts and bequests receive very different tax treatment, and the gap is worth understanding before you move shares to family.

The Step-Up in Basis at Death

When someone inherits stock, the cost basis resets to fair market value on the date of the original owner’s death. Every dollar of gain that accumulated during the decedent’s lifetime is wiped out for income tax purposes.15Office of the Law Revision Counsel. 26 USC 1014 – Basis of Property Acquired From a Decedent A parent’s $5 basis stock worth $200 at death becomes $200 basis for the heir. Sell the next day at $200 and no income tax is owed on the gain.

Lifetime Gifts of Stock

Gifts made while the owner is alive carry the original basis to the recipient, so built-in gain transfers along with the shares.16Office of the Law Revision Counsel. 26 USC 1015 – Basis of Property Acquired by Gifts and Transfers in Trust The recipient also inherits your holding period, so no fresh one-year clock starts.17eCFR. 26 CFR 1.1015-1 – Basis of Property Acquired by Gift After December 31, 1920 The strategy pays off when the recipient sits in a lower bracket: an adult family member with modest income may qualify for the 0% long-term rate on a sale where you would have paid 15% or 20%.

For 2026, you can give up to $19,000 per recipient per year without filing a gift tax return or dipping into your lifetime exemption.18Internal Revenue Service. What’s New – Estate and Gift Tax

The Kiddie Tax Limit

Gifting appreciated stock to a young child to exploit their low bracket usually backfires. Kiddie tax rules cover children under 18, 18-year-olds not providing more than half their own support, and full-time students under 24 in the same situation. Once a child’s unearned income exceeds $2,700, the excess is taxed at the parents’ rate.19Internal Revenue Service. Topic No. 553, Tax on a Child’s Investment and Other Unearned Income The gifting strategy works best with adult relatives who genuinely have low income.

Section 1202 for Qualified Small Business Stock

If your shares are in a small C corporation rather than a public company, Section 1202 can shelter a large portion of the eventual gain. Noncorporate holders can exclude up to 100% of the gain on qualified small business stock held at least five years.20Office of the Law Revision Counsel. 26 USC 1202 – Partial Exclusion for Gain From Certain Small Business Stock For stock acquired after July 4, 2025, the cap is the greater of $15 million per issuer or ten times your adjusted basis.

Qualifying shares must meet several conditions:

  • The issuer is a domestic C corporation; S corporations, partnerships, and LLCs taxed as partnerships do not qualify.
  • The corporation’s gross assets did not exceed $75 million at the time of issuance for stock issued after July 4, 2025 (the older $50 million cap applies to earlier issuances).
  • You acquired the shares at original issue, whether for cash, property, or as compensation. Secondary-market purchases don’t count.
  • You hold the shares at least five years for the full 100% exclusion; three years qualifies for 50% and four years for 75%.20Office of the Law Revision Counsel. 26 USC 1202 – Partial Exclusion for Gain From Certain Small Business Stock

The excluded portion is not subject to the 3.8% net investment income tax either, producing a true zero-tax outcome on qualifying gain. In practice this matters for founders, early employees paid in equity, and angel investors in small C corporations.

State Taxes Are Separate

Everything above concerns federal tax. Most states tax capital gains as ordinary income, with rates ranging from 0% in states without an income tax to more than 13% in the highest. A few states treat certain gains specially or offer partial exclusions. Check your own state’s rules before executing any strategy, because a federal 0% rate does not guarantee a state 0% rate.