To calculate capital gains tax, subtract your cost basis — what you paid for the asset plus certain buying costs and improvements — from your net sale proceeds, then multiply the taxable gain by the rate that matches your holding period and income. In one line: capital gains tax = taxable gain × applicable capital gains rate. Assets held one year or less produce short-term gains taxed at ordinary income rates; assets held longer than a year qualify for long-term rates of 0%, 15%, or 20% for most U.S. filers in 2026, plus a possible 3.8% surtax at higher incomes. This guide walks through every step, with a worked stock example and a capital gains tax home sale example that shows how the Section 121 exclusion can wipe out the tax entirely.
A note on scope: the figures below reflect U.S. federal rules for tax year 2026 (returns filed in early 2027) and are educational only, not personalized tax advice. Thresholds change every year, so confirm current numbers with the IRS or a tax professional before you file.
Before you multiply anything, you need one fact: how long you held the asset.
The clock runs from the day after you acquire the asset to the day you dispose of it. If you are anywhere near the one-year line, run the exact dates through our date calculator before you sell — crossing that line changes the rate on your entire gain, not just part of it.
Net proceeds = Sale price − Selling costs
For stocks, selling costs are broker commissions and transaction fees. For real estate, they include agent commissions, title insurance, transfer taxes, attorney fees, and other charges listed on the settlement statement. These costs reduce your taxable gain, so keep the paperwork.
Cost basis = Purchase price + Buying costs + Capital improvements − Depreciation claimed
For securities, basis is what you paid plus the purchase commission. For property, add closing costs from the original purchase and the cost of capital improvements — a new roof, an addition, a major remodel. Ordinary repairs and maintenance do not count toward basis; they are treated as year-to-year expenses instead.
Subtract the acquisition date from the sale date. One year or less is short-term; more than one year is long-term. If you reinvested dividends or bought in several lots, each lot has its own basis and holding period — your broker statement or Form 1099-B shows both.
Multiply the gain by the long-term rate your taxable income falls into (0%, 15%, or 20%), or by your marginal ordinary rate if the gain is short-term. Remember that taxable income is measured after deductions, so your gross salary and your taxable income are usually different numbers.
High earners may owe the 3.8% net investment income tax (NIIT) once modified adjusted gross income exceeds $200,000 (single) or $250,000 (married filing jointly) — statutory thresholds that are not indexed for inflation. Most states tax gains as ordinary income. You report gains on Form 8949 and Schedule D with your federal return, and your broker reports the same figures to the IRS on Form 1099-B.
Here is the complete calculation in one place:
Net proceeds = Sale price − Selling costs
Adjusted basis = Purchase price + Buying costs + Improvements − Depreciation
Capital gain = Net proceeds − Adjusted basis
Capital gains tax = Taxable gain × Applicable rate (+ NIIT and state tax where they apply)
Maya, a single filer, buys 100 shares at $40 each in March 2025 and pays a $10 commission, giving her a basis of $4,010. In May 2026 she sells all 100 shares at $90, paying a $15 selling fee.
Now flip the timing. If Maya had sold the same shares in January 2026, the gain would have been short-term and taxed at her marginal ordinary rate — potentially 22% or more. Simply waiting past the one-year mark cut her bill substantially. That is how powerful the holding-period rule is.
Owner-occupied homes get a break no stock enjoys: the Section 121 exclusion. If you owned the home and lived in it as your main residence for at least two of the five years before the sale, you can exclude up to $250,000 of gain ($500,000 for married couples filing jointly).
Amount realized = Selling price − Selling costs
Gain = Amount realized − Adjusted basis (price paid + improvements)
Taxable gain = Gain − Exclusion ($250,000 single / $500,000 married)
Example 1 — the exclusion covers everything. Priya and Dev bought their home in 2018 for $340,000 and later spent $30,000 on a kitchen renovation and bathroom remodel, bringing basis to $370,000. In 2026 they sell for $610,000 and pay $36,600 in agent commission and closing costs.
A six-figure gain, fully shielded — which is why this exclusion is one of the most valuable provisions in the tax code. Wondering what the proceeds might buy next? Our guide to how much house you can afford runs the affordability math step by step.
Example 2 — the gain exceeds the exclusion. Ana, single, sells her home for $640,000 with $30,000 in selling costs. She paid $270,000 years ago and put $30,000 into improvements, so her basis is $300,000.
Two fine-print points for any capital gains tax home sale calculation. First, only capital improvements add to basis — repainting, repairs, and routine maintenance do not. Second, if you rented the property out or claimed depreciation (for a home office, for example), the depreciation portion is generally recaptured and taxed at up to 25%, and it does not benefit from the exclusion. The IRS walks through all of these rules — including the two-of-five-years test and special situations involving divorce, widowhood, and job moves — in Publication 523, Selling Your Home.
Under the IRS's 2026 inflation adjustments, the long-term rates for single filers, based on taxable income, are:
Married couples filing jointly get roughly double the 0% and 15% ranges (about $98,900 and $613,700). Three caveats matter. These thresholds are based on taxable income — after deductions — so a single filer earning a $90,000 salary may still sit in the 15% band rather than the 20% band. Long-term gains on collectibles top out at 28%. And the 3.8% NIIT can apply on top of these rates. Because the IRS revises the brackets every year, verify the current figures on the IRS capital gains topic page before you rely on them.
The chart below plots the three long-term bands for single filers in 2026.
A capital gains calculation is really three small subtractions and one multiplication — the hard part is gathering the right inputs. Use our date calculator for holding periods and the percentage calculator for gains and returns, then apply the rate bands above. And if a sale leaves you with extra cash, putting it toward expensive balances is one of the surest returns available — our guide to paying off credit card debt compares payoff strategies side by side. As always, this article is education, not tax advice; a CPA or the IRS publications linked above can confirm how the rules apply to your situation.
Subtract your cost basis (purchase price plus fees) from the net sale price to get the gain, confirm whether you held the shares more than one year, then multiply by the matching rate. In the example above, Maya's $4,975 long-term gain taxed at 15% cost her $746.25 in federal tax.
Only on gain above the Section 121 exclusion — $250,000 for single filers and $500,000 for married couples filing jointly. You must have owned and lived in the home as your main residence for at least two of the five years before the sale. In our worked example, Priya and Dev's $203,400 gain was fully excluded.
Long-term gains are taxed at 0%, 15%, or 20% depending on taxable income, with the 15% rate covering the wide middle band where most filers land, plus a 3.8% net investment income tax at higher incomes. Short-term gains are taxed at ordinary income rates, which run up to 37%.
Take the selling price minus selling costs such as agent commissions and closing fees, subtract your adjusted basis (purchase price plus improvements), and subtract the $250,000 or $500,000 exclusion if you qualify. Only whatever gain remains is taxed at capital gains rates.
You owe no capital gains tax, and the loss offsets other gains dollar for dollar. If losses exceed gains, up to $3,000 per year can offset ordinary income, with additional losses carried forward to future tax years.