How to calculate capital gains tax
To calculate capital gains tax: (1) find the gain (net sale price minus cost basis); (2) classify it short-term (held a year or less, taxed as ordinary income) or long-term (0/15/20%); (3) apply the federal rate for your taxable-income band; (4) add the 3.8% NIIT if your income is over the threshold; (5) add your state's capital gains tax. Offset gains with any capital losses first. General information, not tax advice.
Source: IRS Topic No. 409, Capital Gains and Losses. Data as of June 2026.
The five steps
- Gain = net proceeds - cost basis. Basis is purchase price plus fees and improvements.
- Short-term or long-term? Held one year or less is short-term (ordinary rates); over a year is long-term (0/15/20%).
- Federal rate. For long-term, find your band from total taxable income (see how to figure your bracket).
- NIIT. Add 3.8% on the portion of income above the threshold.
- State tax. Add your state's rate - ordinary income in most states, a special rate or exclusion in some, nothing in a few.
Worked example
You bought stock for $20,000 and sold it three years later for $50,000: a $30,000 long-term gain. With $90,000 of other taxable income (single), the gain falls in the 15% federal band: $4,500 federal tax. Your income is under the NIIT threshold, so no NIIT. In a state that taxes gains at 5%, add $1,500. Total: about $6,000, a 20% effective rate. Run your own numbers in the calculator.
Frequently asked questions
How do I calculate capital gains tax?
Subtract your cost basis (purchase price plus improvements and fees) from the net sale proceeds to get the gain. Determine if it is short-term (held a year or less, taxed as ordinary income) or long-term (taxed at 0/15/20%). Apply the right federal rate, add the 3.8% NIIT if your income is high, then add your state's tax.
What is cost basis?
Cost basis is what you paid for the asset plus certain adjustments - commissions, fees, and capital improvements for property. A higher basis means a smaller taxable gain. For inherited assets the basis is generally 'stepped up' to the market value at the date of death.
Can I offset gains with losses?
Yes. Capital losses offset capital gains dollar-for-dollar. If losses exceed gains, you can deduct up to $3,000 of net loss against ordinary income per year and carry the rest forward. This is called tax-loss harvesting.
Related
Last updated: 2026-06-21