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.
- Proceeds. 500 × $95 = $47,500.
- Adjusted basis. 500 × $40 = $20,000.
- Realised gain. $47,500 − $20,000 = $27,500. The holding period is 36 months, so it is long-term.
- Netting. No other sales and no carryover, so the net long-term gain stays $27,500 and net short-term is $0.
- 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.
- Federal capital gains tax. $27,500 × 0.15 = $4,125.
- 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.
- State tax. $27,500 × 0.05 = $1,375.
- 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
| Filing status | 0% rate applies up to | 15% rate applies up to | 20% rate applies above | 3.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.
