Can You Sell Stock and Reinvest Without Capital Gains Tax?

You cannot sell stock and reinvest the proceeds without capital gains tax simply by turning the money around quickly. The IRS treats every sale as its own transaction, and buying new shares a minute later does nothing to erase the gain on the shares you just sold. What can eliminate or defer the tax is where the sale happens and which specific election you make: trades inside a retirement account, losses harvested in the same year, charitable gifts of appreciated shares, Qualified Opportunity Funds, and the small-business stock rules under Sections 1202 and 1045.

Why Reinvesting Doesn’t Change the Tax

A capital gain is realized the moment you sell a security for more than your adjusted basis, which is generally what you paid plus any reinvested dividends or adjustments. Federal law calculates the gain as the difference between what you received and that basis.1Office of the Law Revision Counsel. 26 USC 1001 – Determination of Amount of and Recognition of Gain or Loss Once realized, the full gain is recognized for that tax year unless a specific exception applies. What you do with the cash afterward is a separate decision that does not undo the sale.

Holding period matters before you get to any strategy. Stock held more than a year qualifies for long-term capital gains rates, which top out at 20%.2Internal Revenue Service. Topic No. 409, Capital Gains and Losses Stock held a year or less is taxed as ordinary income, which for most working investors is meaningfully higher. High earners also face a 3.8% Net Investment Income Tax surcharge once modified adjusted gross income passes $200,000 single or $250,000 married filing jointly, and those thresholds are not indexed for inflation.3Internal Revenue Service. Net Investment Income Tax A large sale can push you into the surcharge even if it wouldn’t otherwise apply to you.

Trading Inside a Retirement Account

The cleanest way to sell and reinvest without a tax bill is to do it inside a retirement account. Traditional IRAs, Roth IRAs, 401(k) plans, and similar accounts are tax-sheltered wrappers. You can buy, sell, and rebalance as often as you want, and no individual trade creates a taxable event.4Office of the Law Revision Counsel. 26 USC 408 – Individual Retirement Accounts5Office of the Law Revision Counsel. 26 USC 401 – Qualified Pension, Profit-Sharing, and Stock Bonus Plans

A traditional IRA or 401(k) defers the tax rather than avoiding it: contributions are often deductible, gains grow untaxed, and withdrawals in retirement are taxed as ordinary income. A Roth IRA or Roth 401(k) takes after-tax money in, but qualified distributions come out completely tax-free, including every dollar of investment gain. A distribution is qualified if the account has been open at least five years and you’ve reached age 59½, become disabled, or meet another qualifying condition.6Office of the Law Revision Counsel. 26 USC 408A – Roth IRAs

The tradeoff is access. Contribution limits for 2026 are $7,500 for IRAs and $24,500 for 401(k) plans, with catch-up contributions of $1,100 (IRA) and $8,000 (401(k)) at age 50 and up, and $11,250 for 401(k) participants ages 60 through 63.7Internal Revenue Service. 401(k) Limit Increases to $24,500 for 2026, IRA Limit Increases to $7,500 Pulling money out before 59½ generally triggers a 10% early withdrawal penalty on top of any income tax, with limited exceptions for disability, a first-time home purchase up to $10,000, qualified higher education expenses, and certain emergency distributions.8Internal Revenue Service. Topic No. 557, Additional Tax on Early Distributions From Traditional and Roth IRAs

Offsetting Gains With Losses in the Same Year

In a regular taxable brokerage account, the most widely used way to shrink a capital gains bill is to sell other positions at a loss in the same tax year. Capital losses offset capital gains dollar for dollar, with short-term losses applied against short-term gains first and long-term against long-term.9Office of the Law Revision Counsel. 26 USC 1211 – Limitation on Capital Losses If losses exceed gains, you can deduct up to $3,000 of the excess against ordinary income ($1,500 if married filing separately), and anything left carries forward indefinitely.

Watch the wash sale rule. If you sell a stock at a loss and buy back the same security, or one substantially identical to it, within 30 days before or after the sale, the IRS disallows the loss.10Office of the Law Revision Counsel. 26 US Code 1091 – Loss From Wash Sales of Stock or Securities The 30-day window runs in both directions, which catches investors who reinvest automatically or who use the same ticker across accounts. The disallowed loss is added to the basis of the replacement shares, so it isn’t destroyed, but it stops working as an offset in the current year. To harvest the loss and stay invested in a similar theme, buy a different fund or stock that isn’t substantially identical.

Donating Appreciated Shares Instead of Selling

If you were going to give to charity anyway, giving stock rather than cash sidesteps the gain entirely. Donate stock held more than one year to a qualified charity and you skip the capital gains tax and take a charitable deduction for the shares’ full fair market value. Shares held a year or less only generate a deduction equal to your cost basis.11Internal Revenue Service. Publication 526, Charitable Contributions

The deduction for appreciated stock given to a public charity is capped at 30% of adjusted gross income. You can elect the 50% AGI cap, but only by reducing the deduction to basis, which usually defeats the point. Unused deduction carries forward up to five years. Noncash contributions above $500 require Form 8283 with your return; publicly traded stock uses Section A regardless of amount.12Internal Revenue Service. Instructions for Form 8283 This works especially well for a single position with a large embedded gain that you’d otherwise have to unwind.

Deferring the Gain Through a Qualified Opportunity Fund

A Qualified Opportunity Fund lets you defer capital gains tax by reinvesting the gain into a fund that invests in designated low-income communities.13Office of the Law Revision Counsel. 26 USC 1400Z-2 – Special Rules for Capital Gains Invested in Opportunity Zones You have 180 days from the date of sale to make the investment.

The 2026 detail every QOF investor needs to know: the deferred gain must be recognized no later than December 31, 2026, or when you sell the QOF investment, whichever comes first.14Internal Revenue Service. Invest in a Qualified Opportunity Fund Anyone who deferred a gain in a prior year will see it hit their 2026 return, and anyone considering a new QOF investment in 2026 is entering a deferral window that is effectively closing.

The longer-term benefit remains. Hold a QOF investment for at least ten years and you can elect to step up its basis to fair market value at sale, so appreciation inside the fund is never taxed.15Internal Revenue Service. Opportunity Zones Frequently Asked Questions That exclusion survives even after the underlying deferral period ends. Reporting is on Form 8949 with the QOF election, plus Form 8997 filed each year.16Internal Revenue Service. About Form 8997, Initial and Annual Statement of Qualified Opportunity Fund (QOF) Investments Miss the 180-day deadline or skip the annual Form 8997 and the original gain is taxed immediately.

Qualified Small Business Stock: 1202 and 1045

Investors in certain startups have two of the most generous tax breaks in the code. Both apply to qualified small business stock (QSBS), meaning stock acquired directly from a domestic C corporation with aggregate gross assets of $75 million or less at the time of issuance.17Office of the Law Revision Counsel. 26 US Code 1202 – Partial Exclusion for Gain From Certain Small Business Stock

Under Section 1202, holding QSBS for more than five years lets you exclude up to 100% of the gain when you sell. The 100% exclusion applies to stock acquired after September 27, 2010, and the excluded amount is capped at the greater of $10 million or ten times your adjusted basis in the stock, per issuer. For founders and early employees of a company that gets acquired, this can shelter millions.

Section 1045 is the option if you can’t wait five years. Sell QSBS held more than six months, roll the gain into new qualified small business stock within 60 days, and the entire gain is deferred.18Office of the Law Revision Counsel. 26 USC 1045 – Rollover of Gain From Qualified Small Business Stock to Another Qualified Small Business Stock The 60-day window is strict, with no extensions. You report the rollover on Schedule D by noting the Section 1045 election. If the replacement stock also qualifies as QSBS and you eventually hit five years, Section 1202 can then apply to the rolled-over gain.

Inherited Stock Resets the Basis

Stock passed to an heir gets a basis reset to fair market value on the date of death.19Office of the Law Revision Counsel. 26 USC 1014 – Basis of Property Acquired From a Decedent Every dollar of appreciation during the original owner’s lifetime disappears for tax purposes. Inherit shares worth $200,000 that were bought for $20,000, sell them the next day at $200,000, and you owe nothing on the gain. This isn’t something you can execute during your own lifetime, but it explains why families holding highly appreciated positions sometimes keep them: selling would trigger a large tax, while passing them through an estate wipes it out. If you inherit appreciated stock and want to reallocate, you can generally sell and reinvest with little or no capital gains cost as long as the price hasn’t moved much since the date of death.

What Doesn’t Work, and What Still Applies

Two boundaries are worth stating plainly. First, like-kind exchanges under Section 1031 do not apply to stocks. Since the 2017 tax reform, Section 1031 treatment is limited to real property, and securities were excluded even before that.20Office of the Law Revision Counsel. 26 US Code 1031 – Exchange of Real Property Held for Productive Use or Investment There is no general tax-deferred stock swap outside the specific programs above.

Second, state tax is a separate bill. Most states tax capital gains as ordinary income, with rates from 0% in states with no income tax to over 13% in the highest-tax states. Federal deferrals and exclusions do not automatically flow through to your state return unless your state has adopted matching rules, and many haven’t. Confirm your state’s treatment before assuming a federal break settles the whole account.