Taxes

How to Calculate Capital Gains Tax: From Cost Basis to the Final Bill

Bar chart: federal tax on a $20,000 gain for a single filer in 2026 is $2,918 long-term vs $4,250 short-term at $49k of taxable income, $3,000 vs $4,800 at $150k and $3,760 vs $7,760 at $300k including the 3.8% NIIT

You sell shares you bought for $6,000 and receive $9,000. The gain is roughly $3,000, but the tax on it could be nothing at all, $450 or more than $1,000, depending on how long you held the shares, what else you earned that year and which losses you can set against it. Capital gains tax is not one flat rate. It is a short calculation in four steps: work out the gain, decide whether it is short-term or long-term, apply the right rate to the right slice of your income, then net off your losses. This guide takes you through each step with 2026 federal figures and worked examples, so you can check a broker’s numbers or estimate the bill before you sell.

Step 1: work out the gain

The tax is charged on the gain, not on the sale price. The gain is what you received, after selling costs, minus your adjusted cost basis: what the asset cost you, including the costs of buying it.

Capital gain = [SALE PROCEEDS] − [SELLING COSTS] − [ADJUSTED COST BASIS]
Adjusted cost basis = [PURCHASE PRICE] + [BUYING COSTS] + [REINVESTED DIVIDENDS] − [RETURN OF CAPITAL]

Say you bought 50 shares at $120 with a $5 commission and sold them at $180, paying another $5:

  1. Basis: 50 × $120 + $5 = $6,005.
  2. Net proceeds: 50 × $180 − $5 = $8,995.
  3. Gain: $8,995 − $6,005 = $2,990.

Two items are easy to miss. Dividends you reinvested were taxed in the year you received them, so they increase your basis; leave them out and you pay tax on the same money twice. Distributions labelled “return of capital” do the opposite and reduce the basis. Inherited assets usually take their value on the date of death as basis, while gifts normally keep the giver’s original basis.

The gain is not the same as your return. A $2,990 gain on $6,005 is a 49.8% return over the whole holding period, and our guide to calculating ROI shows how to turn that into an annual figure you can compare. The tax only cares about the dollar amount.

Step 2: short-term or long-term?

The holding period decides which set of rates applies. According to the IRS, if you hold an asset for more than one year before selling it, the gain is long-term; one year or less makes it short-term. You start counting on the day after the purchase, so shares bought on 15 January 2025 become long-term if you sell on 16 January 2026 or later.

Most investors build a position in several purchases, or “lots”, and the lot you sell changes the gain. Suppose you bought 40 shares at $100 in 2023 and 60 more at $150 in 2025, then sell 50 at $170 in 2026, receiving $8,500:

MethodShares treated as soldBasisGain
First in, first out (default)40 at $100 + 10 at $150$5,500$3,000, mostly long-term
Specific identification50 of the 2025 lot at $150$7,500$1,000, short-term if held one year or less
Average cost (funds only)50 at the $130 average$6,500$2,000

If you do nothing, brokers apply first in, first out, which usually sells your oldest and cheapest shares. You can choose specific lots instead, but you must tell the broker at or before the sale. Average cost is only allowed for mutual fund shares and some dividend reinvestment plans. Selecting the expensive lot gives a smaller gain, but that gain may be short-term, so compare the tax rather than the gain.

Tip: Check the acquisition date of each lot before you sell anything held for around a year. Waiting a few days to pass the one-year mark can move the gain from your income tax rate, up to 37%, to 15% for most people.

Step 3: the 2026 federal rates

Short-term gains are taxed as ordinary income at your usual brackets, from 10% to 37%. Long-term gains, and qualified dividends, have their own lower rates of 0%, 15% and 20%. The IRS adjusts the thresholds for inflation every year; these are the 2026 figures from Revenue Procedure 2025-32, based on taxable income, which means after the standard or itemised deduction:

Filing status0% up to15% up to20% above
Single$49,450$545,500$545,500
Married filing jointly$98,900$613,700$613,700
Head of household$66,200$579,600$579,600

These are not rates for your whole income. Your wages, interest and short-term gains fill the brackets first; long-term gains and qualified dividends are stacked on top, and each slice of the gain is taxed at the rate for the band it falls into. The same rule explains why dividend income can be tax-free for a retiree yet taxed at 15% for a salaried worker holding the same shares.

Worked example: stacking a gain on top of income

Take a single filer earning $65,000 in wages who sells shares for a $20,000 long-term gain in 2026. The standard deduction for a single filer is $16,100:

  1. Ordinary taxable income: $65,000 − $16,100 = $48,900.
  2. The gain sits on top, from $48,900 to $68,900.
  3. The first $550 (up to $49,450) is taxed at 0%.
  4. The remaining $19,450 is taxed at 15%: $2,917.50.
  5. Tax on the gain: $2,917.50, an effective rate of 14.6%.

Had the shares been held for less than a year, the same $20,000 would have been taxed as wages: $1,500 at 12% and $18,500 at 22%, or $4,250. Holding past the one-year mark saved $1,332.50. The gap widens as income rises:

Taxable income before the gainLong-term tax on $20,000Short-term tax on $20,000
$48,900$2,917.50$4,250
$150,000$3,000$4,800
$300,000 (with 3.8% NIIT)$3,760$7,760

At the bottom of the scale the 0% band does real work. A married couple filing jointly with $60,000 of taxable income who realise a $30,000 long-term gain end up at $90,000, under the $98,900 limit, and owe no federal tax on the gain at all.

Losses, netting and the $3,000 rule

Losses are netted against gains before any rate is applied, in a fixed order:

  1. Short-term losses offset short-term gains, and long-term losses offset long-term gains.
  2. A net loss in one group then offsets a net gain in the other.
  3. If the overall result is a loss, up to $3,000 a year ($1,500 if married filing separately) reduces your ordinary income, and the rest carries forward with no time limit.

Example: a $6,000 short-term gain, a $4,000 long-term gain and a $9,000 long-term loss. The long-term side nets to a $5,000 loss, which wipes out $5,000 of the short-term gain, leaving $1,000 taxed as ordinary income. Netting the loss against the short-term gain is the best outcome, because that gain would have been taxed at your full rate.

Two rules limit loss claims. A paper loss does not count; you have to sell. And the wash sale rule disallows a loss if you buy the same or a substantially identical security within 30 days before or after the sale. The loss is not gone: it is added to the basis of the new shares, but you cannot use it this year. Losses on personal-use property, such as your car or your home, are never deductible.

Tip: If you want to harvest a loss but stay invested, switch to a similar fund that tracks a different index rather than buying the same one back. Reinvested dividends in the original fund within the 30-day window can also trigger a partial wash sale.

The extras: NIIT, state tax and special rates

The federal rate is rarely the whole bill. Check these before you settle on a number:

  • Net investment income tax. An extra 3.8% applies to the smaller of your net investment income and the amount by which your modified AGI exceeds $200,000 (single or head of household) or $250,000 (married filing jointly). These thresholds are fixed in law and not indexed, so more people reach them every year.
  • State income tax. Most states tax capital gains as ordinary income, at rates up to 13.3% in California. A few, such as Texas, Florida and Nevada, have no income tax, and some offer partial exclusions.
  • Higher federal rates. Gains on collectibles such as art, coins and physical gold are taxed at up to 28%. Depreciation you claimed on a rental property is recaptured at up to 25% when you sell.
  • Your home. If you owned and lived in it for two of the last five years, up to $250,000 of gain ($500,000 for a married couple) is excluded.

Cryptocurrency follows the same property rules: every sale, swap or purchase paid in crypto is a disposal with its own gain or loss, and the 2025 tax year is the first with broker reporting on Form 1099-DA. Our crypto tax guide covers the events that trigger tax and how to track basis across wallets.

Checking your numbers: forms and the calculator

Your broker sends Form 1099-B early in the year, listing each sale, the proceeds and, for shares bought since 2011, the cost basis. Each sale goes on Form 8949, the totals go on Schedule D, and the tax on long-term gains is worked out with the Qualified Dividends and Capital Gain Tax Worksheet in the Form 1040 instructions. Compare the 1099-B basis with your own records: shares transferred between brokers, old employee stock and reinvested dividends are where the gaps usually appear.

For a quick estimate, our capital gains calculator takes the purchase and sale price, the quantity and the fees and applies the rate you choose. It was built for crypto, but the maths is identical for shares: open the 50-share example above, which shows a $2,990 gain and $448.50 of tax at 15%, then enter your own figures. It applies one rate to the whole gain, so use the stacking method above when a gain straddles two bands.

Legal ways to pay less

  • Hold for more than a year. The cheapest saving available, as the worked example shows.
  • Use the 0% band. In a low-income year, such as between jobs or early in retirement, realise gains up to the 0% limit and buy back immediately. The wash sale rule applies to losses only, so you reset your basis higher at no cost.
  • Harvest losses. Sell losing positions to offset gains you have already realised, keeping the wash sale window in mind.
  • Give appreciated shares, not cash. Donate long-held shares to charity and you avoid the gain while deducting the full market value if you itemise.
  • Use tax-advantaged accounts. Trades inside a 401(k), IRA or HSA create no capital gains at all; our guide to tax-advantaged accounts compares them.
  • Spread large sales. Selling across two tax years can keep each slice in a lower band and under the NIIT threshold.

Limits worth knowing

  • Inflation is taxed too. The gain is measured in nominal dollars, so part of a long-term gain may simply be inflation. Our article on the real rate of return shows how to see what you actually earned.
  • Thresholds move every year. The figures here are for 2026; check the current year’s amounts before you rely on them.
  • Other income interacts. A large gain raises your AGI, which can reduce credits, increase the taxable share of Social Security benefits and raise Medicare premiums two years later.
  • This is federal and general. State rules, the alternative minimum tax and special assets such as small-business stock or options are outside this guide. For a large or complicated sale, a tax professional is worth the fee.

References

Frequently asked questions

Subtract your adjusted cost basis (purchase price plus buying costs) from the sale proceeds after selling costs to get the gain. If you held the asset for more than a year, apply the long-term rates of 0%, 15% or 20% to the part of the gain in each band of your taxable income; if not, it is taxed at your ordinary income rates. Net any losses first.
For a single filer, long-term gains are taxed at 0% up to $49,450 of taxable income, 15% up to $545,500 and 20% above. For married couples filing jointly, the limits are $98,900 and $613,700. Short-term gains are taxed at ordinary rates from 10% to 37%, and the 3.8% NIIT can apply on top for higher incomes.
It depends on your other income and holding period. A single filer with $48,900 of taxable income would pay $2,917.50 on a $20,000 long-term gain, because the first $550 falls in the 0% band and the rest is taxed at 15%. The same gain held for less than a year would cost $4,250.
Yes. Losses first offset gains of the same type, then the other type. If you still have a net loss, up to $3,000 a year can be deducted from ordinary income, $1,500 if married filing separately, and the rest carries forward to future years. Buying the same security back within 30 days triggers the wash sale rule and delays the loss.
Cripto Adicto, founder of WealthCalcApp
Cripto Adicto · Founder of WealthCalcApp · 6+ years in crypto & finance

Passionate about finance and investing, with more than 6 years of hands-on experience in the crypto world. He shares analysis and financial education on his YouTube channel, Cripto Adicto.

Watch on YouTube →

Estimate the tax on your sale

Enter the purchase and sale price, quantity and fees to see the gain, the tax owed and what you keep after tax.

Open the Capital Gains Calculator →

Capital Gains Tax = Gain × the Rate for Each Band

To calculate capital gains tax, subtract your adjusted cost basis from the net sale proceeds, decide whether you held the asset for more than a year, then stack the gain on top of your other taxable income: in 2026 a single filer pays 0% on long-term gains up to $49,450, 15% up to $545,500 and 20% above, while short-term gains are taxed as ordinary income. Net your losses first and use the capital gains calculator for a quick estimate.