How capital gains tax works on stocks in the US

TrackMyShares Team

Every time you sell a stock for more than you paid, the IRS wants its share. Capital gains tax is the tax you owe on the profit from selling investments, and understanding how it works is essential for making smart decisions about when to sell, how long to hold, and how to minimize your tax bill.

In this guide, we break down how capital gains tax applies to stocks in the US, walk through the current tax rates, and show you how to calculate your gains accurately.

Disclaimer: This article is for informational purposes only and does not constitute financial or tax advice. Consult a qualified tax professional before making investment decisions based on tax considerations.

Selling stocks triggers capital gains or losses

When you sell a stock, you either make a profit (capital gain) or take a loss (capital loss). The amount of the gain or loss depends on the difference between what you paid for the stock (your cost basis) and what you received when you sold it.

If you bought shares at $50 each and sold them at $65 each, you have a capital gain of $15 per share. If you sold at $40 instead, you would have a capital loss of $10 per share.

Capital gains are only "realized" when you sell. If your stock has gone up in value but you have not sold it, that is an unrealized gain and is not taxable. You only owe tax when you actually complete the sale.

This distinction matters for tax planning. You control when you realize gains and losses, which gives you the ability to manage your tax bill by timing your sales strategically.

Short-term vs long-term capital gains

The single most important factor in determining your capital gains tax rate is how long you held the stock before selling. The IRS divides capital gains into two categories based on your holding period.

Short-term capital gains

If you held the stock for one year or less before selling, the gain is classified as short-term. Short-term capital gains are taxed at the same rate as your ordinary income, which means they are subject to the same federal income tax brackets that apply to your salary, wages, and other earned income.

For many investors, this means short-term gains are taxed at a significantly higher rate than long-term gains. If you are in the 32% tax bracket, for example, your short-term capital gains are also taxed at 32%.

Long-term capital gains

If you held the stock for more than one year before selling, the gain is classified as long-term. Long-term capital gains receive preferential tax treatment, with rates that are substantially lower than ordinary income tax rates for most taxpayers.

The holding period is calculated from the day after you purchased the stock to the day you sell it. If you bought shares on January 15, 2025, you would need to hold them until at least January 16, 2026, for the gain to qualify as long-term.

This one-year threshold is a key consideration when deciding whether to sell. If you are sitting on a gain and are close to the one-year mark, waiting a few extra days or weeks could save you a meaningful amount in taxes.

2026 tax rates for capital gains

Short-term capital gains rates

Short-term capital gains are taxed as ordinary income. The 2026 federal income tax brackets are:

Tax rateSingle filersMarried filing jointly
10%Up to $12,400Up to $24,800
12%$12,401 - $50,400$24,801 - $100,800
22%$50,401 - $105,700$100,801 - $211,400
24%$105,701 - $201,775$211,401 - $403,550
32%$201,776 - $256,225$403,551 - $512,450
35%$256,226 - $640,600$512,451 - $768,700
37%Over $640,600Over $768,700

Long-term capital gains rates

Long-term capital gains are taxed at preferential rates:

Tax rateSingle filersMarried filing jointly
0%Up to $49,450Up to $98,900
15%$49,451 - $545,500$98,901 - $613,700
20%Over $545,500Over $613,700

The difference between short-term and long-term rates can be dramatic. A single filer earning $150,000 in taxable income would pay 24% on short-term gains but only 15% on long-term gains. On a $10,000 gain, that is the difference between $2,400 and $1,500 in tax, saving $900 just by holding for more than a year.

Net investment income tax (NIIT)

Higher-income taxpayers may also owe the Net Investment Income Tax (NIIT), an additional 3.8% tax on investment income. This tax applies to the lesser of your net investment income or the amount by which your modified adjusted gross income (MAGI) exceeds certain thresholds:

  • Single filers: $200,000
  • Married filing jointly: $250,000
  • Married filing separately: $125,000

Net investment income includes capital gains, dividends, interest, rental income, and royalties. If your MAGI exceeds the threshold, the 3.8% NIIT is applied on top of the regular capital gains rate.

For example, if you are a single filer with $220,000 in MAGI and $30,000 of that comes from long-term capital gains, the NIIT applies to $20,000 (the amount exceeding the $200,000 threshold). That adds $760 in additional tax on top of your regular capital gains tax.

How to calculate your capital gain or loss

The basic formula is straightforward:

Capital Gain (or Loss) = Sale Price - Cost Basis

Your cost basis is the amount you originally paid for the stock, including any commissions or fees paid at the time of purchase. Your sale price is the total amount you received from the sale, minus any selling fees or commissions.

Worked example

Suppose you bought 200 shares of a stock at $50 per share, paying a $10 commission. Your total cost basis is:

  • 200 shares x $50 = $10,000
  • Plus $10 commission = $10,010 total cost basis

Later, you sell all 200 shares at $65 per share, paying a $10 commission. Your net sale proceeds are:

  • 200 shares x $65 = $13,000
  • Minus $10 commission = $12,990 net proceeds

Your capital gain is:

  • $12,990 - $10,010 = $2,980 capital gain

If you held the shares for more than one year, this would be a long-term gain taxed at 0%, 15%, or 20% depending on your total taxable income. If you held them for one year or less, it would be a short-term gain taxed at your ordinary income rate.

Cost basis methods

When you buy the same stock multiple times at different prices, you need a method to determine which shares you are selling. The cost basis method you choose directly affects the size of your gain or loss.

FIFO (First In, First Out)

This is the default method used by most brokers. It assumes you sell your oldest shares first. If your earliest purchases were at lower prices and the stock has risen over time, FIFO tends to produce larger gains because you are selling the cheapest shares.

LIFO (Last In, First Out)

This method assumes you sell your most recently purchased shares first. If your most recent purchases were at higher prices, LIFO can result in smaller gains (or larger losses), which may reduce your tax bill.

Specific identification

This method lets you choose exactly which shares (or "lots") to sell. It offers the most flexibility for tax optimization because you can select the lots that produce the most favorable tax outcome.

For a deeper comparison of these methods with worked examples, see our guide on cost basis methods for stocks.

Wash sale rule overview

The wash sale rule is an important IRS regulation that prevents investors from claiming a tax loss if they repurchase the same or a "substantially identical" security within 30 days before or after the sale.

If you sell a stock at a loss and buy it back within this 61-day window (30 days before, the day of sale, and 30 days after), the loss is disallowed for tax purposes. The disallowed loss is added to the cost basis of the replacement shares, so it is not permanently lost, but it is deferred.

This rule has significant implications for tax-loss harvesting strategies. For a complete explanation of how the wash sale rule works, including examples and common pitfalls, read our detailed guide on the wash sale rule explained.

Capital losses: the $3,000 deduction and carryforward rules

Capital losses are valuable because they can offset your capital gains dollar for dollar. Here is how the IRS handles losses:

  1. Losses offset gains of the same type first. Short-term losses offset short-term gains, and long-term losses offset long-term gains.
  2. Excess losses offset gains of the other type. If you have more short-term losses than short-term gains, the excess offsets long-term gains (and vice versa).
  3. Up to $3,000 of net losses can offset ordinary income. If your total capital losses exceed your total capital gains for the year, you can deduct up to $3,000 of the net loss against other income like wages or salary ($1,500 if married filing separately).
  4. Unused losses carry forward indefinitely. Any net capital loss exceeding the $3,000 annual limit carries forward to future tax years. You can use carried-forward losses to offset gains or deduct $3,000 per year until they are fully used.

Worked example

Suppose in a given tax year you have:

  • $8,000 in long-term capital gains
  • $5,000 in short-term capital losses
  • $6,000 in long-term capital losses

First, short-term losses offset short-term gains. You have no short-term gains, so the full $5,000 short-term loss carries over. Next, long-term losses offset long-term gains: $8,000 gain minus $6,000 loss = $2,000 net long-term gain. The $5,000 short-term loss then offsets the remaining $2,000 long-term gain, leaving you with $3,000 in net short-term losses. You can deduct the full $3,000 against ordinary income this year, with nothing to carry forward.

Reporting capital gains on your tax return

When you sell stocks, your broker sends you a Form 1099-B by mid-February of the following year. This form reports each sale, including the sale date, proceeds, cost basis (for covered securities), and whether the gain or loss is short-term or long-term.

You then use this information to complete:

  • Form 8949 (Sales and Other Dispositions of Capital Assets), where you list each individual sale
  • Schedule D (Capital Gains and Losses), which summarizes your total gains and losses and calculates the net amount

For a step-by-step walkthrough of this process, see our guide on how to report stock sales on your taxes.

How TrackMyShares helps with capital gains tracking

Tracking capital gains across multiple purchases, different holding periods, and various cost basis methods can get complicated quickly. TrackMyShares simplifies this by handling the calculations automatically.

Automatic short-term and long-term classification

Every time you record a sale, TrackMyShares automatically classifies the gain or loss as short-term or long-term based on the holding period. You can see at a glance how much of your realized gains fall into each category.

Cost basis tracking at the lot level

TrackMyShares tracks each purchase as a separate tax lot, recording the purchase date, quantity, and price. When you sell, you can see exactly which lots are being sold and how the cost basis method affects your gain. The platform supports FIFO and specific identification methods.

Tax reports

The capital gains tax report generates a complete summary of your realized gains and losses for any calendar year, broken down by holding. The report shows gross proceeds, cost basis, gain or loss, and holding period classification for each sale, giving you the data you need to file your taxes or share with your accountant.

Tax-loss harvesting tool

The built-in tax-loss harvesting feature scans your portfolio for unrealized losses that could offset your realized gains. It estimates potential tax savings based on your marginal tax rate and flags any wash sale concerns.

Prices updated throughout the day

TrackMyShares provides prices updated throughout the day for all US-listed stocks and ETFs, so your gain and loss figures stay current as the market moves.


Understanding how capital gains tax works is the first step toward managing your tax bill effectively. Whether you are deciding when to sell, which cost basis method to use, or how to harvest losses, having accurate data is essential.

Sign up for TrackMyShares to track your capital gains, generate tax reports, and stay on top of your tax obligations throughout the year.