Finance · 5 min read
How Is Capital Gains Tax Calculated? Step-by-Step Guide
Capital gains tax is calculated by subtracting your cost basis from the sale price to find the gain, then applying either your ordinary income tax rate or a lower long-term rate depending on how long you held the asset. Our capital gains tax calculator runs through this math automatically, but it helps to see where the number actually comes from.
Step one: find your cost basis
Cost basis is generally what you originally paid for an asset, including purchase price plus certain costs like broker commissions or reinvested dividends that were already taxed. For a stock bought at $50 a share and sold at $80 a share, the basis is $50 and the taxable gain is $30 per share, not the full $80.
Step two: figure out your holding period
How long you held the asset before selling determines which set of rates applies. Hold an asset for one year or less and any profit counts as a short-term gain. Hold it for more than one year and the profit counts as a long-term gain, which is taxed far more favorably.
Short-term rates
Short-term gains are taxed as ordinary income, at whatever federal bracket your total income places you in, up to 37% at the top for 2024. There's no special discount for a short-term gain: it's added to your other income and taxed the same as wages would be.
Long-term rates
- 0%: taxable income up to roughly $47,000 for single filers (2024)
- 15%: the bracket most filers land in
- 20%: taxable income above roughly $518,900 for single filers (2024)
These thresholds shift slightly each year for inflation, so treat them as a guide rather than a locked-in number for the current tax year.
The net investment income tax
Higher earners may owe an additional 3.8% net investment income tax on top of the regular capital gains rate. This applies once modified adjusted gross income passes $200,000 for single filers or $250,000 for married couples filing jointly, and it's calculated on whichever is smaller: your net investment income or the amount your income exceeds the threshold.
Offsetting gains with losses
Capital losses offset capital gains dollar for dollar in the same tax year, and any losses left over after that can offset up to $3,000 of ordinary income annually. Losses beyond that $3,000 cap carry forward to future tax years indefinitely, which is why investors sometimes sell losing positions deliberately near year-end, a strategy generally called tax-loss harvesting.
Watch out for the wash sale rule
If you sell a security at a loss and then buy the same or a substantially identical security within 30 days before or after that sale, the IRS disallows the loss under the wash sale rule. The disallowed amount doesn't just vanish: it gets added to the cost basis of the new position, which defers the benefit rather than eliminating it. The rule only applies to losses, so it has no effect if you're selling at a profit.
State taxes are separate
Everything above covers federal tax only. Most states also tax capital gains, usually by folding the gain into your regular state taxable income rather than applying a separate lower rate the way the federal system does, though a handful of states charge no income tax at all. Check your own state's rules alongside these federal numbers for a complete picture.
Putting it together
Say you bought shares for $10,000, sold them two years later for $16,000, and have no other gains or losses that year. Your gain is $6,000, taxed at the long-term rate that matches your income bracket rather than your ordinary rate, since you held the position past the one-year mark. Swap in your own numbers and holding period on the calculator above to see the estimated tax on a specific sale.
Frequently asked questions
How is capital gains tax calculated?
Subtract your cost basis, what you originally paid, from the sale price to find your gain, then apply either your ordinary income rate for a short-term gain or the lower long-term rate if you held the asset more than one year.
What's the difference between short-term and long-term capital gains tax?
Short-term gains, from assets held one year or less, are taxed as ordinary income. Long-term gains, from assets held more than one year, are taxed at 0%, 15% or 20% depending on your taxable income.
Can I offset capital gains with losses?
Yes. Capital losses offset capital gains dollar for dollar, and up to $3,000 of any remaining net loss can offset ordinary income each year, with the rest carried forward to future years.