Investing & Retirement Performance, Risk & Investment Costs IRC §1(h) & §1411 · 2025 tax year

Investment Capital Gains Tax Calculator

Enter what you paid, what you sold for, how long you held, and your income, and this calculator returns the tax bill on the sale. It splits your result into long-term and short-term, nets it against other gains and any loss carryover the way Schedule D does, stacks the long-term portion through the 0%, 15% and 20% bands of IRC §1(h), adds the 3.8% net investment income tax under §1411 where your modified AGI crosses the threshold, and applies a flat state rate. It works for a gain or a loss: a net loss produces the §1211(b) deduction against ordinary income and the amount that carries forward.

Calculator

This calculator runs in your browser. Enable JavaScript for live results — the inputs, formula and worked example below remain fully readable without it.

Inputs this calculator takes, with typical values
InputWhat to enterExample
Shares soldThe number of shares or units disposed of in this sale; fractional shares are fine.500
Adjusted cost basis per shareWhat you paid per share including commissions, taken from the basis column of your broker's Form 1099-B.40 $
Net sale price per shareProceeds per share after selling commissions and fees, as reported on Form 1099-B.95 $
Holding periodTime between your trade date and your sale date; anything over 12 months is treated as long-term.36 months
Filing statusSets the long-term rate thresholds, the ordinary bracket table and the NIIT threshold.Single
Taxable income before this saleForm 1040 line 15 without this sale — AGI after your standard or itemised deduction.165000 $
State tax rate on the gainYour state's marginal rate on capital gains; enter 0 for a state with no income tax.5 %
Other short-term gains this yearNet of all your other sales held 12 months or less; enter a loss as a negative number.0 $
Other long-term gains this yearNet of all your other sales held more than 12 months; enter a loss as a negative number.0 $
Capital loss carryover from prior yearsEnter as a positive number from line 6 or line 14 of last year's Schedule D worksheet.0 $
Modified AGI before capital gainsUsed only for the 3.8% NIIT test; it is normally your AGI before any deduction, so larger than taxable income.190000 $
Ordinary marginal rate for short-term gainsLeave on Auto unless you want to force a single flat rate onto the short-term portion.Auto — stack through the bracket table

It returns

  • Total tax on the gain — Federal capital gains tax plus the 3.8% NIIT plus state tax. A negative figure is the tax saved by a net loss.
  • Net taxable capital gain — This sale plus your other gains, after netting short against long and applying any loss carryover.
  • Federal capital gains tax — Long-term portion at 0/15/20% plus any short-term portion at ordinary rates.
  • Net investment income tax (3.8%)
  • State tax
  • Cash left after tax — Gross proceeds from this sale minus every tax shown above.
  • Effective rate on the gain — Total tax divided by the net taxable gain. Shown only when the year nets to a gain.
  • Loss carried to next year

The formula

Tax=GSTtord+0.15G15+0.20G20+0.038min(NII,MAGIT)+tstateGnet
G=(PsellPbasis)N
G0=min(GLT,max(0,T0O))

In plain text: Tax = G_ST · t_ord + 0.15·G_15 + 0.20·G_20 + 0.038 · min(NII, MAGI − T) + t_state · G_net

  • G_STNet short-term capital gain, taxed as ordinary income ($)
  • t_ordYour ordinary marginal rate, applied by stacking the gain on top of taxable income (decimal)
  • G_15, G_20Portions of the net long-term gain that fall in the 15% and 20% bands; the portion below the zero-rate ceiling is taxed at nothing ($)
  • NIINet investment income — here, the net capital gain ($)
  • MAGIModified adjusted gross income including the gain ($)
  • TNIIT threshold: $200,000 single or head of household, $250,000 joint, $125,000 separate ($)
  • t_stateYour state's marginal rate on the gain (decimal)
  • G_netNet capital gain after netting short against long and applying carryovers ($)

Rate bands are the 2025 figures under IRC §1(h); the 3.8% surtax is IRC §1411. The calculator assumes ordinary 0/15/20% treatment, not the 28% collectibles rate or the 25% unrecaptured §1250 rate.

Updated Category Performance, Risk & Investment Costs Verified against published test cases Reading time 14 min

What a capital gain is, and why two of them exist

A capital gain is the difference between what you receive for an asset and your adjusted basis in it. Sell 500 shares bought at $40 for $95 and you have realised $27,500. Nothing is taxed until you sell: an unrealised gain, however large, has no tax consequence, which is why the sale date is the single most controllable variable in your investment tax bill.

Federal law taxes that $27,500 through one of two completely separate rate systems, and which one applies turns on a single fact — how long you owned the asset. Hold it for more than one year and the gain is long-term, taxed under IRC §1(h) at 0%, 15% or 20%. Hold it for one year or less and the gain is short-term, taxed under IRC §1222 as ordinary income at your marginal rate, which for 2025 tops out at 37%. There is no gradual transition. A sale on day 365 and a sale on day 367 can differ by more than fifteen percentage points on the same dollar of profit.

Two further layers sit on top. The net investment income tax of IRC §1411 adds 3.8% once modified adjusted gross income passes $200,000 for a single filer, $250,000 for a joint return or $125,000 for married filing separately — thresholds fixed in statute since 2013 and never indexed, so each year of wage growth pulls more sellers into them. Then your state takes its share, and most states that levy an income tax give a long-term gain no preferential rate at all — they tax it at the same rate as salary.

How the calculation actually runs: netting first, then stacking

You do not tax each sale in isolation. Schedule D nets everything first, in a fixed order, and only the survivor is taxed.

Step one — net within each column. Add all your short-term gains and losses together to get one net short-term figure, and do the same for long-term. Step two — net the columns against each other. If one column is negative and the other positive, the loss reduces the gain dollar for dollar. A $6,000 net short-term loss against a $20,000 net long-term gain leaves $14,000 of long-term gain, and nothing short-term. Step three — apply any carryover from prior years, which keeps the short-term or long-term character it had in the year it arose; this page applies the figure you enter to the short-term column first and spills the excess into the long-term column, which changes the character split but never the net total. Step four — if the final result is still negative, §1211(b) lets you deduct up to $3,000 of it against ordinary income ($1,500 if married filing separately) and carry the rest forward indefinitely.

Only when a net gain survives does rate stacking begin, and this is the part most estimates get wrong. Long-term capital gain does not have its own bracket ladder running from zero. It is stacked on top of your ordinary taxable income. Picture a column: ordinary income fills it from the bottom, short-term gain sits on that because it is ordinary income too, and long-term gain floats on top. The zero-rate ceiling for a single filer in 2025 is $48,350 of total taxable income. If your ordinary income alone already reaches $165,000, there is no room left underneath, and the whole long-term gain starts in the 15% band.

That stacking rule is also why a large gain can be taxed at two rates at once. Push the top of the column past $533,400 (single) and every dollar above that line is taxed at 20% while the dollars below it stay at 15%. The calculator splits the gain at each boundary rather than applying one blended rate.

The 3.8% surtax uses a different and narrower base: 3.8% of the lesser of your net investment income and the amount by which modified AGI exceeds the threshold. Cross the threshold by $17,500 while realising a $27,500 gain and the surtax applies to $17,500, not to the whole gain. Getting this comparison the right way round matters — using the gain alone overstates the surtax for anyone straddling the line.

Worked example: 500 shares bought at $40, sold at $95 after three years

You are single, your taxable income before the sale is $165,000, your modified AGI before the sale is $190,000, and your state taxes the gain at a flat 5%. You sell 500 shares held for 36 months.

  1. Proceeds. 500 × $95 = $47,500.
  2. Adjusted basis. 500 × $40 = $20,000.
  3. Realised gain. $47,500 − $20,000 = $27,500. The holding period is 36 months, so it is long-term.
  4. Netting. No other sales and no carryover, so the net long-term gain stays $27,500 and net short-term is $0.
  5. Stack it. Ordinary taxable income is $165,000, already above the $48,350 zero-rate ceiling, so none of the gain is taxed at 0%. The top of the stack is $165,000 + $27,500 = $192,500, comfortably below the $533,400 line where 20% starts. All $27,500 therefore sits in the 15% band.
  6. Federal capital gains tax. $27,500 × 0.15 = $4,125.
  7. NIIT test. Modified AGI including the gain is $190,000 + $27,500 = $217,500. That exceeds the $200,000 single threshold by $17,500. Net investment income is $27,500. The surtax applies to the smaller figure: $17,500 × 0.038 = $665.
  8. State tax. $27,500 × 0.05 = $1,375.
  9. Total. $4,125 + $665 + $1,375 = $6,165, an effective rate of $6,165 ÷ $27,500 = 22.4% on the gain. Cash left from the sale is $47,500 − $6,165 = $41,335.

Now change one input. Sell at 11 months instead of 36 and the gain becomes short-term. Stacked on $165,000 of ordinary income the whole $27,500 sits inside the 24% federal band, which runs from $103,350 to $197,300 for a single filer, so the federal tax becomes $27,500 × 0.24 = $6,600 instead of $4,125. The NIIT and the state tax do not change. That single difference in timing is worth thousands of dollars on this trade, which is the practical reason the one-year line is worth planning around.

Reading the result: what your effective rate is telling you

The headline number to watch is the effective rate on the gain, because it collapses four interacting systems into one figure you can compare across decisions. For a long-term seller it runs from 0%, when the whole gain fits under the zero-rate ceiling, up to 20 + 3.8 = 23.8% federal before any state tax, and higher again once a state with a double-digit top rate is added. A short-term seller in the top bracket can reach 37 + 3.8 = 40.8% federal.

Three specific readings deserve attention. First, if any of your gain shows in the 0% band, you have found the single most valuable planning space in the code: realising gains deliberately up to the ceiling and immediately repurchasing resets your basis higher at no federal cost, and no wash-sale rule blocks it because wash-sale treatment under §1091 applies to losses, not gains. Second, if the NIIT appears at all, check how far past the threshold you are — if the excess is small, splitting the sale across two tax years may remove the surtax entirely from one of the halves. Third, if the calculator shows a loss carryforward, that figure is an asset. It shelters future gains at their full rate with no time limit, so it belongs in your plan the same way an unrealised gain does.

Holding rather than selling defers the tax and lets the whole pre-tax balance keep compounding, which you can quantify with the CAGR calculator or the inflation-adjusted return calculator. Tax is only one drag on a portfolio; the expense ratio drag calculator shows the other one, which compounds every year rather than once at sale.

2025 long-term capital gains rate thresholds and NIIT thresholds

Taxable income at which each long-term rate begins for the 2025 tax year (returns filed in 2026). Thresholds are total taxable income including the gain, because the gain stacks on top of ordinary income. NIIT thresholds are modified AGI and are not indexed for inflation.
Filing status0% rate applies up to15% rate applies up to20% rate applies above3.8% NIIT starts at MAGI
Single$48,350$533,400$533,400$200,000
Married filing jointly$96,700$600,050$600,050$250,000
Head of household$64,750$566,700$566,700$200,000
Married filing separately$48,350$300,000$300,000$125,000

Long-term thresholds are the inflation-adjusted 2025 figures published by the IRS; the NIIT thresholds are fixed in IRC §1411 and have not changed since the tax took effect.

Which authorities this follows

The rate structure is IRC §1(h) with the 2025 inflation-adjusted thresholds published by the IRS; the holding-period definition and netting order are IRC §1222 and the Schedule D instructions; the $3,000 annual loss allowance is IRC §1211(b) with the carryover rule in §1212(b); and the 3.8% surtax is IRC §1411, reported on Form 8960. Where a figure is indexed, this page uses the 2025 tax year. If you are filing for a different year, the shape of the calculation is identical but every threshold moves.

What this calculator does not account for

  • Special asset classes with their own rates. Collectibles — art, coins, bullion and most physically backed metal ETFs — carry a maximum 28% long-term rate under §1(h), and the depreciation you claimed on rental real estate comes back as unrecaptured §1250 gain at up to 25%. Both are higher than the 20% ceiling this page assumes.
  • Wash sales. If you buy a substantially identical security within 30 days before or after selling at a loss, §1091 disallows the loss and rolls it into the basis of the replacement shares. Enter only losses that survive that test, or your carryforward will be overstated.
  • Basis you have not adjusted. Reinvested dividends raise basis, return-of-capital distributions lower it, and splits change per-share basis without changing total basis. Brokers report basis for covered shares bought since 2011 or 2012 depending on asset type; older lots are frequently wrong on the 1099-B.
  • A loss you cannot use. The $3,000 allowance is capped at your taxable income, and states differ on whether they mirror it at all.
  • Which lot you sold. Specific identification usually beats FIFO when you hold lots with very different bases, but the election must be made at the time of sale, not on the return. This calculator takes whatever basis you enter.
  • Qualified small business stock. Gain on §1202 stock may be partly or wholly excluded, which changes the answer entirely.
  • State conformity and residency. The single state rate here is a simplification: some states tax gains as ordinary income, a few grant exclusions, some have no income tax at all, and moving between states mid-year raises sourcing questions this cannot answer.
  • Knock-on effects of a higher AGI. A large gain can push you past income-related Medicare premium surcharges, phase out education credits, or increase the taxable portion of Social Security — costs that never appear on Schedule D but are real.
  • Estimated tax timing. Tax on a gain is generally due in the quarter you realise it. A large sale in Q1 with no estimated payment can produce an underpayment penalty even if you pay in full by April.

Where this sits among the other tools

Use this calculator when the sale is already decided and you need the number to set aside.

If you are selling because a position is down and you want the tax benefit, the deliberate version of that trade is loss harvesting — model it with the tax-loss harvesting calculator, which handles the wash-sale window and the value of the carryforward rather than a single sale. If you are choosing between a taxable bond and a municipal one, the comparison you want is the tax-equivalent yield calculator, since municipal interest escapes both the ordinary rate and the NIIT. If the asset sits in a retirement account, none of this applies at all: no capital gains tax arises inside an IRA or 401(k), and distributions come out as ordinary income, which is the arithmetic behind a Roth conversion. And if the holding pays income while you own it, the ongoing tax is a separate calculation from the exit tax — start with the dividend yield calculator.

One structural point worth carrying away: the capital gains system rewards patience twice. It defers the tax until you choose to trigger it, and it cuts the rate roughly in half once you cross a year. Those two features together mean that after-tax return and pre-tax return diverge more the more you trade, and that gap is invisible in every performance figure your broker shows you.

Key terms

Adjusted basis
What you paid for the asset, adjusted for commissions, reinvested dividends, return-of-capital distributions, splits and any prior wash-sale additions. It is the number subtracted from proceeds to get the gain.
Holding period
Measured from the day after your trade date through the date of sale. Long-term treatment requires more than one year, so a sale on the anniversary itself is still short-term.
Net investment income
Interest, dividends, capital gains, rents, royalties and passive business income, less allocable expenses. Wages, self-employment income and retirement account distributions are excluded from it, though they do raise the modified AGI used in the threshold test.
Capital loss carryover
The part of a net capital loss you could not deduct this year. It carries forward indefinitely and keeps the short-term or long-term character it had in the year it arose, entering the next year's Schedule D on line 6 or line 14 alongside that year's own losses.
Rate stacking
The rule that long-term gain is layered on top of ordinary income when deciding which long-term band it falls in, rather than being taxed on its own from zero.

Frequently asked questions

How long do I have to hold a stock to get the long-term rate?

More than one year. The clock starts the day after your trade date and the sale must occur after the first anniversary of that day, so selling exactly one year later is still short-term. Because the difference between the two systems can exceed fifteen percentage points, checking the trade date before you sell is one of the highest-value minutes in investing. This calculator treats a holding period over 12 months as long-term.

Is the 15% capital gains rate applied to my whole gain?

Only if the whole gain fits inside the 15% band once it is stacked on your ordinary income. Long-term gain is layered on top of taxable income, so part of it can be taxed at 0% and part at 15%, or part at 15% and part at 20%, in the same sale. The calculator splits the gain at each threshold and shows how much sits in each band, which is why the effective rate is rarely exactly 15%.

Do I owe the 3.8% net investment income tax on the whole gain?

No — the surtax applies to the lesser of your net investment income and the amount by which your modified AGI exceeds the threshold. If a joint filer with $240,000 of MAGI realises a $30,000 gain, MAGI becomes $270,000, which is $20,000 over the $250,000 threshold, so the 3.8% applies to $20,000 rather than $30,000. The thresholds are $200,000 single or head of household, $250,000 joint and $125,000 married filing separately, and none of them is indexed for inflation.

What happens to a capital loss I cannot use this year?

It carries forward indefinitely. You first net losses against gains of the same character and then across characters, and only if a net loss survives do you deduct up to $3,000 against ordinary income ($1,500 if married filing separately). Everything above that limit rolls into next year with its short-term or long-term character intact. Losses do not expire and they are not lost at death for the decedent's final return, though they do not pass to heirs.

Does selling at a loss and buying back immediately work?

Not for the loss. Section 1091 disallows a loss when you acquire a substantially identical security within 30 days before or after the sale, including purchases in your IRA and automatic dividend reinvestments. The disallowed loss is added to the basis of the replacement shares, so it is deferred rather than destroyed. The mirror-image trade with a gain is not restricted at all — there is no wash-sale rule for gains.

What effective tax rate is normal on a stock sale?

For a long-term sale by a middle-to-upper-income filer in a state with an income tax, an all-in effective rate in the high teens to low twenties is typical: 15% federal, up to 3.8% surtax and a state rate of a few percent. Below the zero-rate ceiling it can be 0%. Above the 20% threshold the federal charge alone is 23.8% with the surtax, before your state takes anything. A short-term sale in the top ordinary bracket reaches 40.8% federal.

Should I enter my cost basis from the 1099-B or my own records?

Start with the 1099-B, then check it. Brokers must report basis for covered securities — generally stock acquired from 2011 and mutual fund or DRIP shares from 2012 — but lots transferred between brokers, inherited or gifted shares, and anything older are often reported as non-covered with no basis at all. Reinvested dividends are the most commonly missed adjustment, and omitting them makes you pay tax on money you already paid tax on.

Are gains inside my IRA or 401(k) taxed here?

No. Selling a position inside a traditional IRA, Roth IRA, 401(k) or HSA produces no capital gain for tax purposes and never appears on Schedule D. Traditional accounts convert everything to ordinary income when distributed; Roth accounts distribute qualified withdrawals tax free. This calculator is for taxable brokerage accounts only, which is also why holding your highest-turnover strategies inside a retirement account is worth real money.

Can I spread a large sale across two years to pay less?

Often yes, because both the rate bands and the NIIT threshold reset each year. Splitting a gain that would push you into the 20% band or well past the surtax threshold can keep more of it in the 15% band and reduce the surtax base in each year. Run the calculator twice with the split amounts and compare the two totals against the single-year figure — and weigh the answer against market risk over the intervening months.

References