How Capital Gains Tax Works (And How to Cut It)

Selling stocks or funds? Learn how capital gains tax works, how tax-loss harvesting helps, and how to avoid the wash sale rule.

12 min read Miscellaneous Financial Blogs

What Is Capital Gains Tax, and When Do You Actually Owe It?

The first time you sell an investment for a profit in a regular (taxable) brokerage account, you may get an unwelcome surprise the following spring: a tax bill. That's because understanding how capital gains tax works is one of the most important, and most overlooked, parts of investing outside a retirement account. The good news is that it's not as complicated as it looks once you learn a handful of key ideas.

In this article, you'll learn how gains and losses are actually taxed, why how long you hold an investment can change your tax rate dramatically, and how a strategy called tax-loss harvesting can turn a losing investment into a tax advantage. We'll also cover the wash-sale rule, a trap that catches many first-time investors off guard, and how the IRS lets you "net" your gains and losses against each other each year.

None of this is about avoiding tax you owe, it's about understanding the rules well enough to make informed, unrushed decisions instead of guessing. Let's start with the basics.

A capital gain is the profit you make when you sell an investment, a stock, a mutual fund, an ETF, a bond, crypto, or similar asset, for more than you paid for it. That original purchase price (plus certain adjustments like reinvested dividends or reinvested capital gains distributions) is called your cost basis. Your gain, in simple terms, is:

Sale price minus cost basis equals capital gain (or loss)

A key point that trips up a lot of new investors: you don't owe capital gains tax just because an investment went up in value. Tax is only triggered when you actually sell (or otherwise "realize") the gain. An investment that has grown in value but that you still hold is said to have an unrealized gain, no tax is due on paper gains. This is one reason "buy and hold" investors often have more control over their tax bill than frequent traders: you get to choose, within limits, when you trigger a taxable event.

If you sell at a loss instead of a gain, that's a capital loss, and as you'll see below, losses aren't just bad news. They can actually work in your favor at tax time.

Short-Term vs. Long-Term Capital Gains: Why the Holding Period Matters

Once you know you have a gain, the next question the IRS asks is: how long did you hold the investment before selling it? The answer sorts your gain into one of two buckets, and the difference between them can be significant.

Short-Term Capital Gains (Held One Year or Less)

If you buy an investment and sell it within one year or less, any profit is a short-term capital gain. Short-term gains are taxed at your ordinary income tax rate, the same graduated rates that apply to your paycheck. Depending on your total income, that could mean a federal rate anywhere from 10% up to 37%.

Long-Term Capital Gains (Held More Than One Year)

If you hold the investment for more than one year before selling, the profit qualifies as a long-term capital gain, which gets preferential tax treatment. Instead of the ordinary income brackets, long-term gains are taxed at one of three flat rates: 0%, 15%, or 20%, depending on your taxable income, according to the IRS's current capital gains tax guidance.

As a general guide for the 2026 tax year (based on IRS inflation-adjusted thresholds), single filers pay 0% on long-term gains up to roughly $49,450 of taxable income, 15% on income up to roughly $545,500, and 20% above that; the thresholds are higher for married couples filing jointly (roughly $98,900 and $613,700). Because these thresholds are adjusted for inflation each year, always check the current-year IRS figures or a recent reputable source before relying on exact numbers for your own return.

High earners should also be aware of the Net Investment Income Tax (NIIT), an additional 3.8% federal tax that can apply to investment income, including capital gains, once modified adjusted gross income exceeds certain thresholds (around $200,000 for single filers and $250,000 for married couples filing jointly).

The takeaway: holding an investment for just a little longer, past the one-year mark, can meaningfully lower the tax rate on your profit. This is one of the simplest, most legal tax strategies available to everyday investors.

How Do Capital Gains "Stack" on Top of Your Ordinary Income?

A common point of confusion: capital gains aren't taxed in isolation. The IRS calculates your ordinary income first (wages, interest, self-employment income, and so on), and then "stacks" your long-term capital gains on top of that income to figure out which capital gains bracket applies.

In practice, this means your ordinary income effectively fills up the lower brackets first, and your capital gains sit on top, taxed at whatever rate corresponds to that higher total income level. This is why the same $10,000 long-term gain might be taxed at 0% for one person and 15% for another, it depends on how much other income they already have.

Short-term gains work differently: they're simply added to your ordinary income and taxed right alongside it at your regular marginal rate, with no special stacking rate of their own.

This stacking effect is also why the timing of a big sale can matter. Selling a large long-term position in a year when your other income is unusually low (for example, a gap between jobs, or your first year of retirement) could mean some or all of the gain is taxed at 0%. Selling in a high-income year could push part of the gain into the 15% or 20% bracket.

What Is Tax-Loss Harvesting?

Tax-loss harvesting is the strategy of intentionally selling an investment that has declined in value in order to "realize" the loss for tax purposes, and then using that loss to offset gains (or a limited amount of ordinary income) elsewhere on your tax return.

Here's the basic idea in plain terms:

  • You own an investment that's currently worth less than you paid for it.
  • You sell it, locking in a capital loss.
  • That loss can offset capital gains you've realized elsewhere, dollar for dollar, reducing the total tax you owe.
  • If your losses are larger than your gains, up to $3,000 of the excess loss ($1,500 if married filing separately) can be deducted against your ordinary income each year.
  • Any loss beyond that annual limit isn't lost, it "carries forward" to future tax years, where it can offset future gains or ordinary income under the same rules.

Tax-loss harvesting doesn't mean giving up on investing, or abandoning your strategy because something is temporarily down. Many investors who harvest a loss reinvest the proceeds right away, often into a similar (but not "substantially identical", more on that below) investment, so their overall portfolio strategy and market exposure stay roughly the same while the tax loss is still captured.

It's worth remembering: tax-loss harvesting is most useful in a regular taxable brokerage account. It generally doesn't apply inside tax-advantaged accounts like a 401(k), 403(b), or IRA, because gains and losses inside those accounts aren't taxed (or deducted) year to year in the same way.

How Does Netting Gains and Losses Actually Work in a Given Tax Year?

If you sold multiple investments during the year, some for a profit, some for a loss, the IRS doesn't just add everything up in one pile. There's a specific order of operations, often called "netting":

  • Step 1: Short-term gains and short-term losses are netted against each other, producing a net short-term gain or loss.
  • Step 2: Long-term gains and long-term losses are netted against each other separately, producing a net long-term gain or loss.
  • Step 3: If one category is a net gain and the other is a net loss, the two results are combined (netted against each other) to arrive at your overall capital gain or loss position for the year.
  • Step 4: If the final result is a net loss, up to $3,000 (or $1,500 if married filing separately) can offset ordinary income that year, with any remainder carried forward to future years.

Why does this matter? Because the character of the loss affects what it offsets most efficiently. A net short-term loss offsets short-term gains first, which is especially valuable, since short-term gains would otherwise be taxed at your higher ordinary income rate. Many investors choose which specific losing positions to sell partly based on this, for instance, prioritizing the sale of a position with a short-term loss if they also have short-term gains to offset.

Brokerages typically report this information to you (and the IRS) on Form 1099-B at year-end, and it flows onto IRS Schedule D and Form 8949 on your tax return, which is where the netting calculation ultimately happens.

What Is the Wash Sale Rule (And How Can It Cancel Your Tax Loss)?

The wash sale rule is an IRS rule designed to prevent investors from claiming a tax loss while, in substance, never actually leaving the investment. It's explained in detail in IRS Publication 550 on wash sales. Here's how it works:

If you sell a security at a loss, and then buy that same security, or one the IRS considers "substantially identical", within 30 days before or 30 days after the sale (a 61-day window in total), the loss is disallowed for tax purposes. Instead, the disallowed loss gets added to the cost basis of the newly purchased shares, effectively deferring the tax benefit rather than eliminating it entirely.

A few important details:

  • "Substantially identical" generally means the same stock, or the same mutual fund/ETF, not just something similar. Two different S&P 500 index funds from different providers are often treated with caution by advisors, though the IRS has not published a precise bright-line test for funds; when in doubt, many investors choose a fund that tracks a different index entirely to stay clearly clear of the rule.
  • The rule applies across all of your accounts, including your spouse's accounts and your IRAs, not just the single account where you made the sale.
  • Buying the security back inside a tax-advantaged account, like an IRA, right after selling it at a loss in a taxable account can still trigger the wash sale rule, and in that scenario, the loss may be permanently disallowed rather than deferred.
  • The rule can also apply if you had a standing dividend reinvestment plan that automatically repurchased shares of the same investment during the window, even if you didn't place a manual trade.

How to Avoid Triggering a Wash Sale

  • Wait at least 31 days before repurchasing the identical security.
  • Reinvest the proceeds into a similar, but not identical, investment (for example, swapping one broad-market index fund for a different index fund tracking a different benchmark) to stay invested in roughly the same part of the market.
  • Double-check activity across every account you and your spouse hold, not just the one where you sold.

Getting caught by the wash sale rule isn't a penalty in the sense of a fine, but it does mean the loss you were counting on to offset a gain doesn't count this year, which can be a frustrating surprise if you didn't know the rule existed.

Frequently Asked Questions

Yes. In a taxable brokerage account, selling an investment for a profit is a taxable event whether or not you withdraw the cash or immediately reinvest it in something else. Reinvesting doesn't erase the gain, it just means you now have a new cost basis in whatever you bought next.

As of current IRS guidance, the wash sale rule has historically applied specifically to "securities," and the IRS has treated many cryptocurrencies as property rather than securities, meaning the traditional wash sale rule has not clearly applied to them in the same way. However, this is an evolving area, proposals have circulated in Congress to extend wash sale treatment to digital assets, and some brokers or exchanges may apply similar reporting. Because rules here can change, check current guidance or talk to a tax professional before assuming crypto is exempt.

Any net capital loss beyond the amount you can deduct against ordinary income in the current year (generally $3,000, or $1,500 if married filing separately) carries forward indefinitely to future tax years, where it can offset future capital gains or, again, up to the annual limit against ordinary income.

It's most commonly associated with down markets or down positions, but it can be relevant any time you hold an individual position with an unrealized loss, even in a year when the broader market is up. Some investors also do it near year-end as part of an annual review of their portfolio.

Not necessarily. Many states tax capital gains as ordinary income with no special long-term rate at all, while a few states have no personal income tax whatsoever. Always check your specific state's rules separately from the federal rules described here.

Yes, if you had a net capital loss last year that exceeded the amount you were allowed to deduct, that carryforward loss is available to offset gains (or ordinary income, within the annual limit) in the current year and future years until it's fully used.

Keep Building Your Financial Confidence

Understanding the mechanics of capital gains tax, tax-loss harvesting, and the wash sale rule is a big step toward making calm, informed decisions with your taxable investments, instead of guessing at tax time. If you'd like a hands-on way to see how holding periods, gains, and losses interact for your own numbers, explore Financial Confidence's Capital Gains & Tax-Loss Planning Tool, and keep building your knowledge with more free lessons at Financial Confidence Schools.

Explore Free Courses
This article is meant to help you understand how capital gains tax generally works, it's educational content, not personalized tax or investment advice. Tax law is detailed, changes over time, and depends on your full financial picture, so before you sell an investment specifically for tax reasons, especially anything involving tax-loss harvesting or the wash sale rule, please talk with a qualified tax professional who can look at your whole return. Read our full disclaimer →
📈
Try the Capital Gains & Tax-Loss Planning ToolEstimate the tax impact of selling investments, compare sale scenarios, and see gain and loss netting before you trade.
Plan My Sale

More in Miscellaneous Financial Blogs