Capital Gains Tax Calculator

Selling stock or funds? This calculator prices the sale the way Schedule D does: ordinary income fills the brackets first, long-term gains stack on top through the 0%, 15%, and 20% bands, losses net in the official order, and the 3.8% NIIT lands on high incomes. All 2026 thresholds.

By Yongwen Wu · Methodology · Last updated October 27, 2026

Your income
The sale
Defaults describe a single filer with 40,000 dollars of wages selling a 30,000 dollar long-term position. The model uses the 2026 standard deduction, the 2026 ordinary brackets, the 2026 long-term breakpoints from Rev. Proc. 2025-32, loss netting in Schedule D order with the 3,000 dollar ordinary-income cap, and the unindexed 200,000 dollar NIIT threshold. It excludes state tax, the Section 121 home-sale exclusion, and collectibles or unrecaptured Section 1250 special rates. All figures are in US dollars.

Gains Are Taxed Where They Stack, Not Where They Sit

The single most common mistake in capital gains planning is treating the 15% rate as flat. It is not. The long-term rates of 0%, 15%, and 20% are bands of total taxable income, and your ordinary income claims the bottom of the stack before your gains get counted. A nurse earning 40,000 dollars and a surgeon earning 400,000 dollars selling the same fund on the same day pay wildly different rates, because the surgeon's wages have already pushed every dollar of gains past the 15% ceiling while the nurse's taxable income leaves most of the 0% band empty. The gain does not carry its own rate; the stack beneath it decides.

That stacking rule is also where the planning opportunities live. A retiree living on savings can realize tens of thousands of dollars of gains per year at a zero federal rate, because low ordinary income leaves the entire 0% band open. A worker one year from a lower-income retirement might defer a bonus-sized sale by twelve months and drop a bracket. And the one-year holding line cuts harder than any bracket: short-term gains are ordinary income, taxed at rates up to 37 percent, before the 3.8% surtax even enters. This calculator runs the full stack so the number you see matches what Schedule D and Form 8960 will produce.

The Math Behind the Calculator

Net short-term = max(Short-term gains − Losses, 0)
Remaining losses = max(Losses − Short-term gains, 0), applied against long-term gains
Net long-term = max(Long-term gains − Remaining losses, 0)
Loss vs. ordinary income = min(excess losses, $3,000), remainder carries forward
Ordinary taxable income = Wages − Standard deduction − loss deduction + Net short-term
Short-term tax = bracket tax with gains − bracket tax without gains
0% band = max($49,450 single / $98,900 MFJ / $66,200 HoH − ordinary taxable, 0)
Long-term tax = 15% × gain in 15% band + 20% × gain above the 15% ceiling
NIIT = 3.8% × min(net investment income, max(MAGI − $200,000 single / $250,000 MFJ, 0))
Total tax on gains = Short-term tax + Long-term tax + NIIT

Variables in plain terms. Wages and other ordinary income are anything that lands in the regular brackets: pay, interest, self-employment profit. Long-term gains come from assets held more than one year, counted as sale price minus basis. Short-term gains from assets held one year or less are folded into ordinary income and taxed at bracket rates. Losses net in the official Schedule D order, against short-term gains first because those carry the worst rates, then long-term, with any leftover capped at a 3,000 dollar deduction against ordinary income per year, 1,500 for married filing separately, and carried forward indefinitely. The 2026 breakpoints come from IRS Rev. Proc. 2025-32: the 0% band ends at 49,450 dollars of taxable income for single filers, 98,900 for joint, 66,200 for head of household, and the 15% band ends at 545,500, 613,700, and 579,600 respectively. The NIIT thresholds of 200,000 and 250,000 dollars of modified AGI have never been inflation-indexed since the tax began in 2013.

A worked example using the defaults

Take the single filer with 40,000 dollars of wages selling a stock position for a 30,000 dollar long-term gain. After the 16,100 dollar standard deduction, ordinary taxable income is 23,900 dollars. The 0% band for a single filer runs to 49,450 dollars of taxable income, so 25,550 dollars of room remains, and the first 25,550 dollars of the gain fills it tax free. The remaining 4,450 dollars sits in the 15% band and costs 667.50 dollars. The NIIT does not apply because modified AGI of 70,000 dollars is far under 200,000. The bill for a 30,000 dollar sale is 667.50 dollars, an effective rate of 2.2 percent. Now suppose the same shares were sold two weeks earlier, at eleven months of holding. The entire gain becomes ordinary income on top of wages, costing 3,950 dollars instead. Holding to long-term treatment saved 3,282.50 dollars, which makes the one-year line the most valuable single day in the tax code.

What Moves the Bill

The same engine run across income levels and sale sizes shows which lever dominates. Each row changes one thing from the default.

ScenarioTax on the gainsEffective rate
Default: single, $40k wages, $30k long-term gain$667.502.23%
Same sale, held 11 months (short-term)$3,950.0013.17%
Default plus $10,000 of losses$0.000.00%
Retired, no wages, $40k long-term gain$0.000.00%
Married jointly, $120k wages, $40k gain$4,335.0010.84%
Single, $220k wages, $50k gain$9,400.0018.80%
Single, $75k wages, $600k gain$113,720.0018.95%

Three rows deserve a pause. The retired row is the quiet windfall of low-income years: with no wages, the entire 40,000 dollar gain fits inside the 49,450 dollar 0% band and the bill is zero, which is why gain harvesting belongs in every early-retirement plan. The 220,000 dollar row shows the surtax working: the gains themselves sit squarely in the 15% band at 7,500 dollars, but modified AGI of 270,000 dollars exceeds the threshold by 70,000 dollars, so 3.8 percent of the 50,000 dollar gain adds 1,900 dollars, pushing the effective rate to 18.8 percent. The 600,000 dollar row is where both top layers engage: 486,600 dollars of the gain pays 15 percent, 113,400 dollars crosses into 20 percent for 95,670 dollars, and the NIIT contributes 18,050 dollars more, a combined 113,720 dollars and an effective rate just under 19 percent.

Losses behave asymmetrically, and the asymmetry matters. Add 10,000 dollars of realized losses to the default and the net long-term gain falls to 20,000 dollars, which now fits entirely in the 0% band: the tax drops from 667.50 dollars to zero, saving more per dollar than the 15% headline suggests. With no gains at all, losses still work but slowly: 20,000 dollars of losses against 75,000 dollars of wages deducts only 3,000 dollars this year, worth about 660 dollars at the 22% bracket, and carries the remaining 17,000 dollars forward to future years. And the NIIT has a cliff with no phase-in: a single filer at exactly 200,000 dollars of wages adding a 20,000 dollar gain owes 760 dollars of surtax on it, because the full gain counts as net investment income the moment MAGI crosses the line.

Planning Levers Before December 31

Most capital gains planning reduces to four moves. Hold past one year, because the short-to-long switch is worth thousands in the examples above and costs nothing but patience. Fill the 0% band deliberately in low-income years, selling appreciated lots up to the breakpoint and, if you wish, buying them back immediately, since the wash-sale rule of IRC Section 1091 blocks repurchasing at a loss but says nothing about repurchasing at a gain. Harvest losses to reset basis, remembering the 30-day repurchase window. And time large sales against the NIIT threshold, because stepping over 200,000 dollars of MAGI taxes the whole gain, not just the excess.

Two adjacent tools extend the picture. The effective tax rate calculator shows your overall rate across wages and deductions, which is the number to compare before and after a planned sale. If the sale was bigger than expected and withholding will not cover it, the tax refund estimator reconciles the full year and shows whether a balance is coming due in April. And for the compounding side of the ledger, the compound interest calculator projects what the after-tax proceeds become if reinvested, a useful reality check before spending a windfall.

Frequently Asked Questions

How is capital gains tax actually calculated?

Your ordinary income, wages minus deductions plus short-term gains, fills the regular tax brackets first. Long-term gains then stack on top of that remaining taxable income, and only the portion that falls past the 0% breakpoint pays 15%, and only the portion past the 15% ceiling pays 20%. In the default example, a single filer with 23,900 dollars of ordinary taxable income has 25,550 dollars of room left in the 0% band, so the first 25,550 dollars of a 30,000 dollar gain is tax free and only the last 4,450 dollars pays 15%, a total of 667.50 dollars.

What is the difference between short-term and long-term gains?

Assets held one year or less produce short-term gains taxed as ordinary income at your normal bracket rates, up to 37 percent. Assets held more than one year get the preferential 0, 15, or 20 percent rates. The holding period starts the day after purchase and includes the sale date, so selling on the one-year anniversary still counts as short-term. In the default scenario the same 30,000 dollar gain costs 3,950 dollars if realized short-term versus 667.50 dollars long-term, so one extra day of holding saves 3,282.50 dollars.

What is the 3.8% Net Investment Income Tax?

NIIT is a separate Medicare-related surtax under IRC Section 1411. It applies at 3.8 percent to the lesser of your net investment income or the amount your modified AGI exceeds 200,000 dollars as a single filer or 250,000 dollars married filing jointly, 125,000 married filing separately. Unlike the capital gains brackets, these thresholds have never been indexed for inflation since 2013, so more people cross them every year. A single filer with 200,000 dollars of wages and a 20,000 dollar gain owes 760 dollars of NIIT on that gain, and a top-bracket investor faces an effective 23.8 percent federal rate on long-term gains.

How do capital losses reduce the bill?

Losses offset gains of the same type first, then cross over: short-term losses absorb short-term gains, and net losses then offset the other category. Beyond that, up to 3,000 dollars of net loss per year, 1,500 for married filing separately, can deduct against ordinary income, with the rest carried forward indefinitely. In the loss example, 20,000 dollars of losses with no gains uses the 3,000 dollar ordinary deduction and carries 17,000 dollars forward. Losses then short-term gains then long-term gains is the netting order this calculator applies. Also note the wash-sale rule: repurchasing a substantially identical security within 30 days disallows the loss under IRC Section 1091.

Do I pay capital gains tax when I sell my house?

Probably not on most of the gain. Section 121 excludes up to 250,000 dollars of gain on a primary residence for a single filer or 500,000 dollars married filing jointly, as long as you owned and used the home as your main residence for at least two of the previous five years. The exclusion generally can be used once every two years. Only the gain above the exclusion flows into this calculation as a long-term gain, and improvements made over ownership raise your basis and shrink the gain.

Will a large sale trigger a penalty if I do not pay estimated tax?

Possibly. A big December sale can push your tax bill past what withholding covers, and brokerage sales have no withholding unless you request it. The safe harbor avoids underpayment penalties if you pay at least 90 percent of the current year's tax through withholding and estimated payments, or 100 percent of last year's tax, 110 percent if your prior-year AGI exceeded 150,000 dollars. If the sale happens late in the year and the deadline has passed, increasing withholding on your final wages can still fix the shortfall because withholding is treated as paid evenly across the year, while estimated payments are credited on their actual dates.

Sources: IRS Rev. Proc. 2025-32 (2026 ordinary brackets, standard deductions, and long-term capital gains breakpoints, Section 3.03); IRC Sections 1411 (NIIT), 1211 (capital loss limitation), 1222 (holding periods), 1091 (wash sales), and 121 (Section 121 home-sale exclusion); IRS Net Investment Income Tax FAQ. Educational estimates only, not tax advice.

Sources

All calculation logic on this page is implemented from the primary documents below. Each one is listed with the figure it supplies, so any rate or threshold in the result can be traced back to its published source.

Not advice. PennyWise Calcs publishes calculators and plain-language summaries of published regulations. Nothing on this page is tax, legal, or investment advice, and it does not replace a licensed professional who knows your full situation.

One practical money tool, every week

Join the PennyWise Calcs newsletter. New calculators and plain-English money math. No spam, unsubscribe anytime.