How to Calculate Capital Gains Tax
Capital gains tax is the tax on the profit from selling an asset for more than it cost, and working it out takes four steps: find the gain, check how long you held the asset, find the rate for your income, and add state tax. The holding period alone can nearly halve the federal bill.
By Jacob Levy, Founder of FigureQuick.com · Last reviewed 2026-11-19
Step 1: Find the gain
Your taxable gain is the sale price minus your cost basis — what you originally paid, plus improvements and selling costs that count toward basis. Sell stock bought for $25,000 for $75,000 and the gain is $50,000. A capital gain is calculated when the asset is sold, not while it rises in value: an unsold gain is unrealised and no tax is due on it. Losses work the other way: selling losers to offset gains, known as tax-loss harvesting, is a lever worth using before year-end.
Step 2: Check the holding period
How long you held the asset decides the federal rate. Held more than a year, it is a long-term gain, taxed at 0%, 15%, or 20% depending on your total taxable income. Held a year or less, it is a short-term gain, taxed at ordinary income rates — the same brackets as wages. If you are a few weeks from the one-year mark, waiting can cut the federal rate nearly in half, but never let the tax tail wag the dog: if the investment has peaked or you need the cash, selling is still the right call.
Step 3: Find your rate
For 2026, a single filer pays 0% on long-term gains on taxable income up to $49,450, 15% up to $545,500, and 20% above that; married couples filing jointly pay 0% up to $98,900 and 15% up to $613,700 (IRS Revenue Procedure 2025-32). The rate is set by total taxable income — other income plus the gain — not by the size of the gain alone. On top of the federal rate, a 3.8% net investment income tax (NIIT) applies when total income passes $200,000 for a single filer or $250,000 for a married couple filing jointly. Your state taxes the gain at its own rate, and states do not give a long-term discount.
Worked example: a long-term gain of $50,000. Sell an asset bought for $25,000 for $75,000 after holding it more than a year, with $115,000 of other income and a 5% state rate. The taxable gain is $50,000. Total income is $165,000, which sits in the 15% long-term band, so the federal tax is $7,500, and the state tax is $2,500 — a total tax of $10,000.00 and net proceeds after tax of $65,000.00. The Capital Gains Tax Calculator reproduces this example exactly.
Worked example: a short-term gain of $40,000. Take a $30,000 purchase sold for $70,000 after holding it a year or less, with $135,000 of other income and a 5% state rate. Short-term gains are taxed at ordinary rates, so the federal rate is 24%: $9,600 federal plus $2,000 state, or $11,600.00 in total, leaving net proceeds of $58,400.00. Holding the asset past the one-year mark would have saved $3,600.00 on this sale. The Capital Gains Tax Calculator reproduces both examples exactly, and the guide The Complete Guide to Taxes: Income Tax, Capital Gains, and Self-Employment Tax covers the rates, the NIIT, and estate tax in full.
Step 4: Add state tax — and check the home exclusion
State tax is the gain multiplied by the state rate you enter, with no long-term discount. A $50,000 gain in a 5% state costs $2,500 whether you held the asset for a month or a decade. One large exception applies to a home: the gain on the sale of a primary residence can be excluded — up to $250,000 for a single filer or $500,000 for a married couple filing jointly — if you owned and lived in the home for at least two of the last five years (IRS, Section 121). A gain above the exclusion is taxed like any other capital gain. The Estate Tax Calculator estimates the separate federal tax on an estate above the exemption, for the other end of the same question — what happens to assets when they pass on rather than when they are sold.
Use this calculator with clients → White-label.
Common mistakes
Three mistakes show up again and again. The first is forgetting the state part of the bill, which has no long-term discount. The second is using the wrong cost basis — improvements and selling costs that count toward basis are often left out, which overstates the gain. The third is selling days before the one-year mark and paying the short-term rate on a gain that would have been taxed at 15% instead of 24%. Each one is avoidable with the numbers in the steps above.
Sources and methodology
Long-term capital gains thresholds for 2026: IRS Revenue Procedure 2025-32. Net investment income tax: 3.8% above $200,000 single or $250,000 joint (IRS). Primary residence exclusion: IRS, Section 121 — up to $250,000 single or $500,000 joint, owned and lived in for two of the last five years. The worked-example arithmetic was computed with the Capital Gains Tax Calculator's own formulas and checked in Python and Node.js against the calculator code. Tax rules change every year — confirm the current figures with the IRS before filing. This guide is educational: it describes what the calculators compute, not advice about which tax choice to make. Last reviewed 2026-11-19.
Frequently asked questions
When is a capital gain calculated?
A capital gain is calculated when the asset is sold, not while it rises in value. The taxable gain is the sale price minus the cost basis — what you originally paid, plus improvements and selling costs that count toward basis. An unsold gain is unrealised and no tax is due on it.
How is the tax rate on a long-term gain decided?
By your total taxable income — other income plus the gain — not by the size of the gain alone. For 2026, a single filer pays 0% on taxable income up to $49,450, 15% up to $545,500, and 20% above that (IRS Revenue Procedure 2025-32). On top of that, a 3.8% net investment income tax applies when total income passes $200,000 single or $250,000 joint, and state tax applies at the state rate with no long-term discount.
Do you pay capital gains tax when you sell your home?
Often not, because of the primary residence exclusion: the gain on the sale of a home can be excluded — up to $250,000 for a single filer or $500,000 for a married couple filing jointly — if you owned and lived in the home for at least two of the last five years (IRS, Section 121). A gain above the exclusion is taxed like any other capital gain, at the long-term rates if you held the home more than a year.
What is the net investment income tax?
The net investment income tax (NIIT) is an extra 3.8% federal tax on investment income, including capital gains, when total income passes $200,000 for a single filer or $250,000 for a married couple filing jointly. It sits on top of the ordinary long-term rate, so a gain in the 20% band costs 23.8% federally at that income level, before state tax.
