You can legally avoid paying taxes on investment gains by holding securities long enough to qualify for preferential capital gains rates, strategically harvesting losses to offset gains, and utilizing tax-advantaged accounts like retirement plans. The simplest path for many investors is timing: if your total taxable income stays below $49,450 (single) or $98,900 (married filing jointly) in 2026, long-term capital gains face a 0% federal tax rate. For example, a retiree with $30,000 in annual Social Security and $15,000 in long-term investment gains could sell appreciated stocks with zero federal capital gains tax liability.
Beyond income-based strategies, the tax code offers multiple methods to defer, reduce, or eliminate capital gains taxes entirely. These include tax loss harvesting, donating appreciated securities to charity, investing in qualified small business stock, reinvesting gains into opportunity zones, and maximizing retirement accounts. These aren’t loopholes—they’re explicit provisions written into federal tax law. Understanding which strategies apply to your situation can save thousands of dollars annually.
Table of Contents
- What Are Long-Term Capital Gains and How Do They Get Taxed?
- Tax Loss Harvesting—Turning Losses Into Tax Savings
- The 0% Capital Gains Rate and Income Planning
- Donating Appreciated Securities Instead of Selling Them
- Qualified Small Business Stock (QSBS) and the Section 1202 Exemption
- Reinvesting Gains Into Opportunity Zones
- Maximizing Retirement Accounts to Trade Tax-Free
- Conclusion
What Are Long-Term Capital Gains and How Do They Get Taxed?
Long-term capital gains are profits from selling investments you‘ve held for more than one year. They’re taxed at preferential rates compared to short-term gains (held one year or less), which are taxed as ordinary income at rates up to 37%. In 2026, long-term capital gains face three federal rates: 0%, 15%, or 20%, depending on your total taxable income. The 0% rate applies to single filers earning $49,450 or less and married couples filing jointly earning $98,900 or less. The 15% rate applies to middle-income filers, while the 20% rate kicks in for high earners. Additionally, high-income investors may face a 3.8% Net Investment Income Tax on top of capital gains.
Here’s a practical example: suppose you bought 100 shares of a stock for $50 each ($5,000 total) and sold them two years later for $100 each ($10,000). Your long-term capital gain is $5,000. If you’re a single filer with $40,000 in other taxable income, your total taxable income would be $45,000—well below the $49,450 threshold. You’d pay 0% federal tax on that $5,000 gain, saving $750 compared to the 15% rate. In contrast, if your other income was $60,000, your total would be $65,000, pushing you into the 15% bracket. You’d owe $750 in federal capital gains tax.

Tax Loss Harvesting—Turning Losses Into Tax Savings
tax loss harvesting is one of the most accessible and powerful ways to reduce investment taxes. The strategy involves intentionally selling investments that have declined in value to realize losses, which you then use to offset investment gains. If your losses exceed your gains in a year, you can deduct up to $3,000 of the excess against ordinary income (like wages or interest). Any remaining losses roll forward indefinitely, providing tax deductions in future years. Here’s how it works in practice: suppose you have a portfolio with a $8,000 gain in Stock A and a $4,000 loss in Stock B. By selling Stock B to harvest the loss, you can offset the $4,000 gain, leaving you with a net $4,000 gain to recognize.
If you had no other losses that year, you’d also deduct the $3,000 difference against ordinary income, potentially saving $900 at a 30% combined federal and state rate. Additionally, if your net investment income exceeds certain thresholds, reducing gains through loss harvesting also reduces the 3.8% Net Investment Income Tax. The main limitation of tax loss harvesting is the wash sale rule: you cannot repurchase the same or a substantially identical security within 30 days before or after the sale. If you do, the IRS will disallow the loss deduction. However, you can immediately buy a similar—but not identical—investment. For example, if you sell a specific stock fund at a loss, you can’t buy the same fund again for 30 days, but you could buy a similar competitor fund in the same sector.
The 0% Capital Gains Rate and Income Planning
For lower-income and middle-income investors, the 0% long-term capital gains rate is a gift often overlooked. In 2026, single filers can realize gains up to $49,450 without owing federal capital gains tax, and married couples can realize gains up to $98,900. This creates a powerful planning opportunity, especially for retirees or investors between jobs. Consider this example: a retired couple receives $30,000 annually from Social Security and has $60,000 of long-term capital gains they want to realize. By selling the appreciated securities, their taxable income becomes $90,000, still below the $98,900 threshold for married couples.
They pay 0% federal capital gains tax on the entire $60,000, saving approximately $9,000 compared to the 15% rate. If they had realized the same gains next year when they returned to work with higher income, they’d face the 15% rate instead. This timing strategy is completely legal and can be used year after year to harvest gains at favorable rates. The opportunity often disappears once your income rises above these thresholds, making it crucial to take advantage in low-income years—such as retirement transitions, sabbaticals, or career changes. Many people miss this opportunity because they focus on total income rather than planning which years to realize which gains.

Donating Appreciated Securities Instead of Selling Them
One of the most underutilized tax strategies is donating appreciated securities directly to charity instead of selling them. When you donate a stock, mutual fund, or other appreciated asset that you’ve held for more than one year, you avoid capital gains tax entirely on the appreciation. You still receive a charitable deduction for the full fair market value—but only if you itemize deductions on your tax return. Here’s the financial benefit: you own 500 shares of a stock now worth $25,000 that you originally bought for $8,000. If you sold the shares, you’d owe 15% federal capital gains tax on the $17,000 gain ($2,550 in taxes) before donating the proceeds.
But if you donate the shares directly to a qualified charity, neither you nor the charity pays capital gains tax on that $17,000 appreciation. You get a $25,000 charitable deduction, potentially saving $7,500 in income taxes if you’re in a 30% combined federal and state bracket. That’s $10,050 in total tax savings versus selling and then donating. The downside is that you must itemize deductions to benefit from the charitable donation. If your standard deduction is larger than your itemized deductions, the strategy loses its tax advantage. Additionally, you lose the basis step-up if the appreciated asset eventually goes to charity through your estate instead—though during life, the donation strategy remains one of the most efficient ways to support causes you care about while eliminating capital gains taxes.
Qualified Small Business Stock (QSBS) and the Section 1202 Exemption
If you’ve invested in a startup or small business, you may qualify for one of the most generous tax breaks in the code: the Section 1202 exemption on Qualified Small Business Stock (QSBS). This provision allows you to exclude a portion or all of your capital gains from federal taxation, depending on how long you’ve held the stock. The exclusion percentages are: 100% if held for 5 or more years; 75% if held for 4 to 5 years; and 50% if held for 3 to 4 years. For stock issued after July 4, 2025, the 100% exclusion is capped at the greater of $15 million or 10 times your basis (cost) in the stock. Additionally, QSBS gains are exempt from the 3.8% Net Investment Income Tax and the Alternative Minimum Tax (AMT).
However, QSBS only applies to shares in C corporations with total assets under $75 million, and you must be an individual shareholder—not a corporation or trust. For example, suppose you invested $50,000 in a startup in 2019, and it sold to a larger company in 2025 for $500,000. Your gain is $450,000. Since you held the stock for six years (more than five), you qualify for the 100% Section 1202 exclusion. You owe $0 federal capital gains tax on that $450,000 gain, saving approximately $67,500 at a 15% rate. This is a legitimate, congressionally-approved strategy designed to encourage investment in small businesses.

Reinvesting Gains Into Opportunity Zones
Opportunity Zones offer another way to defer and reduce capital gains taxes. These are economically distressed areas designated by the federal government, and if you reinvest capital gains into qualified opportunity zone funds, you can defer taxes on those gains. The deferred gains are taxable in 2026 (or when the investment is sold, whichever is earlier), but the mechanism provides a tax deferral that allows your money to compound tax-free in the interim. For instance, you realize a $100,000 long-term capital gain by selling appreciated stocks.
Normally, you’d owe about $15,000 in federal capital gains tax immediately (at the 15% rate). Instead, if you reinvest that $100,000 into a qualified opportunity zone fund within the required timeframe, you defer the $15,000 tax bill. Your investment compounds inside the fund; if it grows to $140,000 over five years, you eventually owe capital gains tax on the original $100,000 gain (when you exit or in 2026), but you keep all the additional growth tax-free. This is most beneficial when you expect the opportunity zone investment to significantly outperform your typical portfolio.
Maximizing Retirement Accounts to Trade Tax-Free
The simplest way to avoid capital gains taxes entirely is to buy and sell investments inside retirement accounts like Roth IRAs, traditional 401(k)s, or SEP IRAs. Inside these accounts, you can trade as frequently as you want without triggering capital gains taxes. Only when you withdraw money do you face tax consequences—and with Roth accounts, qualified withdrawals are tax-free. For example, a 35-year-old investor with a Roth IRA could buy and sell individual stocks dozens of times per year, realizing thousands in gains, without owing a penny in capital gains tax.
All gains compound tax-free. At retirement, she can withdraw the balance with no federal income tax. The same investor with a traditional 401(k) defers taxes on gains until withdrawal, at which point ordinary income tax applies—but again, no capital gains tax during accumulation. The 2026 contribution limits are $7,000 for IRAs and $23,500 for 401(k)s (higher if you’re 50 or older), making these accounts essential for long-term tax-efficient wealth building.
Conclusion
Legally avoiding capital gains taxes requires a combination of timing, strategy selection, and account structure. The most straightforward approaches are realizing gains in low-income years (to access the 0% rate), harvesting losses to offset gains, donating appreciated assets to charity, and maximizing contributions to retirement accounts. More sophisticated strategies—like QSBS exemptions, opportunity zones, and Section 1045 rollovers—apply to specific situations but can deliver substantial savings when available.
The key is to plan proactively rather than reactively. Review your portfolio annually, especially in transition years like retirement or career changes when your income dips. Coordinate with a tax professional to ensure you’re taking advantage of all available strategies and avoiding pitfalls like the wash sale rule. Tax efficiency won’t make you rich, but combined with a solid investment strategy, it can save you tens of thousands of dollars over a lifetime—money that stays in your pocket instead of the IRS’s.




