How Is Capital Gains Tax Calculated?

Capital gains tax is calculated on your profit — the sale price minus your cost basis — and the rate depends on how long you held the asset. Assets held one year or less are taxed at ordinary income rates (10%–37%); assets held longer than a year qualify for the preferential long-term rates of 0%, 15%, or 20%, set by your taxable income. That holding-period distinction is the single biggest lever in the whole calculation. The rest of this guide walks through cost basis, the exact brackets, the home-sale exclusion, and how losses cut your bill.
A capital gain is the profit you realize when you sell a capital asset — stocks, funds, real estate, crypto, or collectibles — for more than you paid. Nothing is taxed until you actually sell; an investment that has risen in value but that you still hold produces an unrealized gain, which the IRS does not touch.
Step 1: Calculate the Gain (Sale Price − Cost Basis)
Your cost basis is what you originally paid for the asset, including commissions and fees, plus the cost of any qualifying improvements (for real estate). The taxable gain is simply:
Capital Gain = Sale Price − Cost Basis
Buy 100 shares at $50 ($5,000 basis) and sell them at $80 ($8,000), and your capital gain is $3,000. You can work out the profit on any trade — including commissions and holding period — with the stock profit calculator.
Step 2: Determine the Holding Period
How long you owned the asset before selling decides which rate applies — and the gap is large:
- Short-term (held one year or less): taxed as ordinary income at your marginal rate, from 10% up to 37%.
- Long-term (held more than one year): taxed at the preferential 0%, 15%, or 20% rate.
The one-year clock starts the day after you buy and includes the day you sell. Crossing that line can cut the tax rate on a gain by more than half, which is why long-term investors are careful not to sell just short of a year.
Step 3: Apply the Long-Term Rate Brackets (2025)
Long-term capital gains have their own brackets, separate from ordinary income. For the 2025 tax year:
| Rate | Single | Married Filing Jointly | Head of Household |
|---|---|---|---|
| 0% | Up to $48,350 | Up to $96,700 | Up to $64,750 |
| 15% | $48,351–$533,400 | $96,701–$600,050 | $64,751–$566,700 |
| 20% | Over $533,400 | Over $600,050 | Over $566,700 |
Source: IRS, Topic No. 409, Capital Gains and Losses and Revenue Procedure 2024-40. Thresholds are based on total taxable income and adjusted annually for inflation.
The brackets stack on top of your ordinary income. If wages already fill the 0% band, additional long-term gains spill into the 15% band. High earners may also owe the Net Investment Income Tax (NIIT) — an extra 3.8% on investment income once modified adjusted gross income exceeds $200,000 (single) or $250,000 (married filing jointly), per IRS Topic 559.
Worked Examples
| Scenario | Gain | Holding Period | Rate | Tax |
|---|---|---|---|---|
| Single, $60K income, sells stock | $5,000 | 18 months (long-term) | 15% | $750 |
| Single, $40K income, sells fund | $5,000 | 2 years (long-term) | 0% | $0 |
| Single, $60K income, sells stock | $5,000 | 6 months (short-term) | 22% (ordinary) | $1,100 |
The middle row shows the power of the 0% bracket: a taxpayer with modest income can realize long-term gains completely tax-free. The bottom row shows the cost of selling early — the same $5,000 gain taxed at 22% instead of 15%.
The Home-Sale Exclusion (Section 121)
Your primary residence gets special treatment. Under Section 121, if you owned and lived in the home for at least two of the last five years, you can exclude up to $250,000 of gain if single or $500,000 if married filing jointly. Only gain above the exclusion is taxable.
Sell a home you bought for $300,000 at $550,000 as a married couple, and the entire $250,000 gain is excluded — you owe nothing. The exclusion applies only to a main home, not rental or investment property. See IRS Topic 701, Sale of Your Home and Publication 523 for the details and partial-exclusion rules.
Using Losses to Cut the Bill
Capital losses are a built-in offset. They first cancel out capital gains dollar-for-dollar. If losses exceed gains, you can deduct up to $3,000 of net loss against ordinary income each year ($1,500 if married filing separately), and carry any excess forward indefinitely. This is the basis of tax-loss harvesting.
One trap: the wash-sale rule disallows a loss if you buy the same or a “substantially identical” security within 30 days before or after the sale. See IRS Publication 550 for the mechanics of losses, basis, and wash sales.
How to Legally Owe Less
- Hold for more than a year. Crossing the one-year mark drops the rate from as high as 37% to 15% or less.
- Use tax-advantaged accounts. Gains inside a Roth IRA or 401(k) are never taxed on sale — see the Roth vs Traditional IRA comparison.
- Harvest losses to offset gains and shave $3,000 off ordinary income.
- Time your income. Realizing gains in a low-income year can land them in the 0% bracket.
Fund investors have an extra wrinkle: exchange-traded funds are structured to minimize the capital-gains distributions that mutual funds pass through. Our sister site breaks down how that works in How Are ETFs Taxed? You can also project the pre-tax growth of an investment with the investment returns calculator.
This article is educational and not individualized tax advice. Capital gains rates, brackets, and exclusion amounts are set by the IRS and change over time — confirm the current figures at IRS.gov or with a tax professional before selling.
Frequently Asked Questions
Calculate Your Trade’s Profit
Enter your buy price, sell price, shares, and commissions to see your exact gain, capital-gains tax, and net return.
Open Stock Profit Calculator →Project Your Investment Growth
Model returns, contributions, and reinvestment to see what your portfolio becomes before taxes.
Open Investment Calculator →