Capital gains tax is the tax you pay on the profit from selling an asset for more than its cost basis. It applies to stocks, bonds, mutual funds, real estate, and other investments, and the rate depends on how long you held the asset and how much taxable income you reported elsewhere.
The mechanics are simple once you separate three things: the gain, your holding period, and your income bracket. Get those right and the calculation is mostly arithmetic.
What is the capital gains tax formula?
The core formula is: sale proceeds minus adjusted cost basis equals taxable gain. Multiply that gain by the applicable rate to get the tax.
Adjusted cost basis starts with what you originally paid. Add commissions, fees, and capital improvements you made.
Subtract any depreciation you claimed (common with rental property). The result is the number you subtract from the sale price.
If you sold stock for $12,000 and your basis was $8,000, your gain is $4,000. If you held it more than a year and your income puts you in the 15% bracket, your tax is $600. Short-term gains on the same $4,000 could be taxed at a higher ordinary rate.
How does the holding period change the rate?
Holding period splits capital gains into two buckets with very different tax treatment. One year or less is short-term; more than one year is long-term.
Short-term gains are added to your ordinary income and taxed at your marginal rate — potentially 22%, 24%, 32% or higher depending on your bracket. Long-term gains use the preferential 0%, 15% or 20% rates. That spread is the main reason investors avoid selling appreciated assets before the one-year mark.
| Holding period | Tax treatment | Rate source |
|---|---|---|
| One year or less | Short-term | Ordinary income brackets |
| More than one year | Long-term | 0%, 15% or 20% |
Long-term rates depend on your taxable income, not the size of the gain. A large gain can push you into a higher capital gains bracket even if your salary is modest. For example, if a $50,000 long-term gain pushes your taxable income from $40,000 to $90,000, part of the gain may be taxed at 0% and the rest at 15%, depending on the year’s bracket thresholds.
Which capital gains rate applies to you?
Long-term capital gains fall into three brackets based on total taxable income. The thresholds shift slightly each year, so check the current IRS figures before you estimate.
- 0% bracket: Applies to lower-income taxpayers. A portion or all of a long-term gain may be untaxed if taxable income falls below the threshold.
- 15% bracket: The middle band for most moderate to upper-middle earners.
- 20% bracket: Reserved for high-income taxpayers above the top threshold.
The gain itself doesn’t determine the bracket — your whole taxable income does. Investors should project year-end income before selling large positions, since adding a gain late in the year can push the total into the next tier.
What is the net investment income tax?
The NIIT is a 3.8% surtax on net investment income, including capital gains, for taxpayers above certain income levels. The thresholds are $200,000 for single filers and $250,000 for married filing jointly.
The surtax applies to the lesser of your net investment income or the amount by which modified adjusted gross income exceeds the threshold. A taxpayer with $250,000 MAGI and $60,000 of capital gains could owe 3.8% on a portion of that gain.
This surtax stacks on top of the regular capital gains rate. A 20% long-term gain plus NIIT effectively becomes roughly 23.8% for high earners. The tax is reported on Form 8960 and flows through to the main return.
How do capital losses reduce the bill?
Realized capital losses offset realized capital gains before tax is calculated. Short-term losses offset short-term gains first; long-term losses offset long-term gains first. Any leftover loss can offset the other category.
If total losses exceed total gains, you can deduct up to $3,000 against ordinary income per year ($1,500 if married filing separately). Remaining losses carry forward indefinitely and can offset future gains.
This is why year-end tax planning matters. Selling a losing position before December 31 can reduce the year’s tax bill on winners. Watch the wash-sale rule: buying back a substantially identical security within 30 days disallows the loss.
How is capital gains tax calculated on a home sale?
Most primary-home sales avoid capital gains tax entirely thanks to the Section 121 exclusion. The gain is excluded if you owned and lived in the home for two of the five years before sale. Married couples filing jointly can exclude up to $500,000; single filers up to $250,000.
Above the exclusion, the excess gain is taxed as a long-term capital gain (assuming you owned the home more than a year). Your basis includes the purchase price plus improvements, closing costs, and selling expenses. Keep receipts for major renovations — they add to basis and reduce the taxable gain.
Property taxes paid on the home may also be deductible, subject to the state and local tax cap. For 2026, the overall SALT deduction limit is $40,400 ($20,200 if married filing separately), reduced for modified AGI above $505,000 ($252,500 married filing separately). Understanding what counts as a deductible property tax — and how it differs from escrow deposits — matters here; see how mortgage payments work for how tax escrow fits into a monthly payment.
Rental property is different. Depreciation claimed during ownership reduces basis, which increases the taxable gain at sale.
Gains on rental property also face depreciation recapture taxed at up to 25%, and rental income and expenses are reported annually. See rental property tax deductions for the annual side of that picture.
Worked example: a long-term stock sale
Suppose you bought 500 shares at $40 each, paying a $10 commission. Basis is $20,010. You sell all 500 shares at $60 each, paying a $10 commission, for net proceeds of $29,990.
The gain is $29,990 minus $20,010, or $9,980. You held the shares for 18 months, so the gain is long-term. Your taxable income puts you in the 15% capital gains bracket, so the federal tax is $9,980 × 15% = $1,497.
If you’d held the shares for only 10 months and your marginal ordinary rate was 24%, the same gain would cost $9,980 × 24% = $2,395.20. Waiting eight more months would have saved roughly $898 in federal tax.
If your MAGI were above $200,000, the 3.8% NIIT would add $9,980 × 3.8% = $379.24, bringing the long-term total to about $1,876.24.
What records do you need?
You need proof of what you paid and when you bought it. Brokerage statements, trade confirmations, and year-end 1099-B forms cover most securities. For real estate, keep closing statements, improvement receipts, and records of any depreciation claimed.
Brokers now report cost basis to the IRS for most covered securities, which simplifies filing. For older holdings or private sales, you’ll need to reconstruct basis from your own records. The IRS generally expects you to keep supporting documents for at least three years after filing, and longer for property.
Common mistakes
- Using the wrong basis. Forgetting commissions, reinvested dividends, or improvements inflates your taxable gain. Depreciation you claimed on a rental also reduces basis, which raises the gain.
- Selling just before the one-year mark. A few days can separate a 15% long-term rate from a 24% short-term rate. Check the trade date and settlement date before selling.
- Ignoring the NIIT. High earners often budget for 15% or 20% and get surprised by the extra 3.8%.
- Forgetting the wash-sale rule. Repurchasing a sold loser within 30 days disallows the loss for the current year.
- Blending short- and long-term gains. They’re taxed differently and reported separately on Schedule D. Keep the buckets straight.
- Missing the home sale exclusion requirements. The two-of-five-year test has exceptions for job changes, health, and unforeseen circumstances, but they must be documented.
If you’re planning a sale and want to see how the after-tax proceeds could compound in a retirement account, run the numbers with the retirement savings calculator. For shorter-term goals, the savings goal calculator shows how much you need to set aside each month. And if you’re deciding how much to invest overall, how much to save for retirement covers the two numbers that drive the answer.