Tax Basics23 min read

How to Calculate Capital Gains Tax: Step by Step From Purchase Price to Your Final Tax Bill

Complete step-by-step guide to calculating capital gains tax. Learn how to find your cost basis, calculate net proceeds, determine your gain or loss, apply the correct tax rate (0%, 15%, or 20%), factor in the NIIT, handle state taxes, and use our free calculators to get your exact number.

How to Calculate Capital Gains Tax: Step by Step From Purchase Price to Your Final Tax Bill
SM

Written by

Sarah Mitchell

Certified Public Accountant (CPA)

DC

Reviewed by

David Chen

Tax Attorney & Legal Editor

Published on

July 23, 2026

Most People Guess Their Capital Gains Tax. That Guess Is Usually Wrong.

When I sit down with clients to review their tax returns, one thing becomes clear almost immediately: most people have no idea how to calculate their capital gains tax correctly. They eyeball it. They ask a friend. They type a number into a random online tool without understanding what the tool is actually doing. And they end up either overpaying because they missed deductions they were entitled to, or underpaying because they forgot a surtax they did not know existed.

A client named Linda called me in a panic last March. She had sold some stock for a $80,000 profit and assumed her tax bill would be about $12,000 at the 15% rate. When her actual tax came back at $18,400, she thought her accountant made a mistake. He had not. What Linda missed was the 3.8% net investment income tax that kicked in because her income exceeded the threshold, plus her state tax of 5%. The 15% federal rate was only part of the story.

This guide walks you through every single step of calculating your capital gains tax, with real numbers and real examples. No guessing. No shortcuts. Just the complete calculation from your purchase price to the final number you owe the IRS.

Our short-term capital gains calculator and long-term capital gains calculator can do the math for you instantly, but understanding the steps helps you catch errors and plan better.

Step 1: Find Your Cost Basis

Your cost basis is the starting point of every capital gains calculation. It is what you paid to acquire the asset, plus certain costs associated with the purchase. The higher your cost basis, the lower your taxable gain. Getting this number right is critical.

Purchase price is the amount you paid for the investment. For stocks, this is the price per share multiplied by the number of shares. For real estate, it is the property purchase price. For cryptocurrency, it is the amount you paid in US dollars at the time of purchase.

Purchase costs that increase your basis include broker commissions, transfer taxes, recording fees, title insurance, survey costs, and legal fees associated with the purchase. These are not separate deductions — they become part of your cost basis.

Improvements add to your basis for real estate. If you built a garage, installed central air, renovated the kitchen, or added a deck, those costs increase your cost basis and reduce your gain. Routine maintenance like painting or fixing a leaky faucet does not count as an improvement. Only permanent additions that add value qualify.

Our guide to capital gains tax for beginners explains cost basis fundamentals if you want a simpler overview before diving into the calculations here.

Special Cost Basis Situations

Inherited assets get stepped-up basis. If you inherited the property, your basis is the fair market value on the date the original owner died, not what they originally paid. This step-up can dramatically reduce your gain. Our guide to capital gains on inherited property explains this in detail.

Gifted assets carry over the giver's basis. If someone gave you the asset, your basis is whatever their basis was. You inherit their cost, not the current market value. If the asset appreciated significantly before you received it, your gain could be surprisingly large.

Stock splits adjust your basis per share. If you bought 100 shares at $50 each and the company did a 2-for-1 split, you now own 200 shares with a basis of $25 each. Your total basis remains $5,000, but the per-share basis changes.

Dividend reinvestment adds to your basis. Every time dividends are automatically reinvested to buy more shares, those purchases create a new cost basis layer. Tracking DRP basis requires keeping records of every reinvestment date and price.

Capital gains tax calculation step by step
4-Step Process for Calculating Capital Gains Tax

Step 2: Calculate Your Net Sale Proceeds

Your net sale proceeds are what you actually receive from the sale after deducting selling expenses. Just like purchase costs increase your basis, selling costs reduce your proceeds.

Sale price is the total amount the buyer pays for the asset. For stocks, multiply the sale price per share by the number of shares sold. For real estate, it is the property sale price.

Selling expenses that reduce your proceeds include broker commissions, real estate agent fees, transfer taxes, escrow fees, title fees on the sale side, advertising costs, legal fees for the sale, and staging costs for real estate. These expenses are subtracted from your sale price before calculating the gain.

Let me put this together with numbers. Suppose you sell a rental property for $450,000. The real estate commission is $27,000 (6%). Closing costs on the sale side are $5,500. Transfer tax is $2,250. Your net sale proceeds are $450,000 - $27,000 - $5,500 - $2,250 = $415,250.

Notice that your net proceeds are significantly lower than the sale price. If you calculated your gain using the full $450,000 without deducting selling expenses, you would overstate your gain by $34,750 and overpay your tax by roughly $5,200 at the 15% rate.

Step 3: Determine Your Gain or Loss

This is where the calculation comes together. Your capital gain or loss equals your net sale proceeds minus your cost basis.

Capital Gain = Net Sale Proceeds - Cost Basis

If the result is positive, you have a capital gain. If it is negative, you have a capital loss.

Full Example Calculation

Let me walk through a complete example so you can see every number in context.

You bought a vacant lot in 2018 for $30,000. You paid $1,500 in closing costs at purchase. Over the years, you spent $8,000 clearing trees and installing a gravel driveway (improvements, not maintenance). Your total cost basis is $30,000 + $1,500 + $8,000 = $39,500.

In 2026, you sell the lot for $150,000. The real estate commission is $9,000. Closing costs on the sale side are $2,500. Your net sale proceeds are $150,000 - $9,000 - $2,500 = $138,500.

Your capital gain is $138,500 - $39,500 = $99,000.

Since you held the lot for more than one year (about 8 years), this is a long-term capital gain.

Capital gains calculation example with real numbers
Complete Calculation Example With Real Numbers

Step 4: Apply the Correct Tax Rate

Now that you know your gain amount and whether it is short-term or long-term, you apply the correct tax rate. This is where the biggest savings opportunities exist.

Long-Term Capital Gains Rates

If you held the asset for more than one year, your gain qualifies for the preferential long-term capital gains rates. For 2026, these rates are:

0% rate applies when your total taxable income (including the gain) falls below about $48,350 for single filers or about $96,700 for married couples filing jointly. If your income is low enough, you pay absolutely zero federal tax on your long-term gains.

15% rate applies to most taxpayers. It covers taxable income between the 0% threshold and about $525,000 for single filers or about $583,750 for married couples. This is the rate that applies to the vast majority of long-term gains.

20% rate applies to high-income taxpayers whose total taxable income exceeds the 15% threshold. It is the top capital gains rate for most assets.

28% rate applies specifically to collectibles like art, coins, antiques, and precious metals. Our collectibles tax guide explains this special rate.

25% rate applies to depreciation recapture on real estate. This is a separate calculation from the regular capital gain. Our real estate investment property tax guide covers depreciation recapture in detail.

Short-Term Capital Gains Rates

If you held the asset for one year or less, your gain is a short-term capital gain taxed at ordinary income rates. These rates are the same brackets that apply to your salary and wages: 10%, 12%, 22%, 24%, 32%, 35%, and 37%.

The difference between short-term and long-term rates can be enormous. On a $100,000 gain, a taxpayer in the 32% ordinary bracket pays $32,000 if the gain is short-term, but only $15,000 if it is long-term. That is a $17,000 difference from holding a few extra days.

Our comparison of short-term versus long-term capital gains shows the rate difference at every income level with exact numbers.

Short-term vs long-term capital gains rates comparison
Rate Difference Between Short-Term and Long-Term Gains

How the Rates Work With Your Other Income

Your capital gains rate is determined by your total taxable income, not just the gain itself. This means your gains and your ordinary income are combined to figure out which bracket applies.

Here is how it works. Your ordinary income fills up the lower brackets first. Then your long-term capital gains sit on top of that income. The rate that applies to each dollar of your gain depends on which bracket that dollar falls into after adding all your income together.

Example: A single filer with $40,000 in salary and a $50,000 long-term capital gain has total taxable income of $90,000. The first $48,350 of income (salary plus some of the gain) falls into the 0% bracket, and the remaining $41,650 of the gain falls into the 15% bracket. The total federal tax on the $50,000 gain is about $6,250 — not $7,500 (15% of the whole gain). The 0% bracket saves this taxpayer $1,250.

This layering effect is why it is so important to understand how capital gains interact with your other income. People who just multiply their gain by 15% often overestimate their tax. Use our long-term capital gains calculator to see the exact calculation for your situation.

Step 5: Add the 3.8% Net Investment Income Tax

If your modified adjusted gross income exceeds $200,000 (single) or $250,000 (married filing jointly), you owe an additional 3.8% net investment income tax on your capital gains. This surtax stacks on top of the regular capital gains rate.

Your effective maximum federal rate on long-term gains becomes 23.8% (20% plus 3.8%) if you are above the NIIT threshold. On short-term gains, the effective maximum is 40.8% (37% plus 3.8%).

The NIIT applies to net investment income, which includes capital gains, dividends, interest, rental income, and certain other investment income. If your net investment income is less than the amount by which your MAGI exceeds the threshold, the tax applies only to the investment income. If your net investment income exceeds that excess, the tax applies to the full investment income amount.

Our complete guide to the net investment income tax explains the thresholds, calculations, and strategies for reducing the NIIT.

Step 6: Calculate State Tax

Most states tax capital gains at the same rate as ordinary income, with no preferential rate for long-term gains. This means your state tax burden can be significant on top of the federal tax.

California taxes everything at ordinary rates up to 13.3%. A California resident with a $100,000 long-term gain pays 15% federal plus 3.8% NIIT plus 13.3% state, for a combined rate of about 32.1%.

New York adds up to 10.9% state tax plus 3.876% city tax for New York City residents. The combined rate on a $100,000 long-term gain can exceed 29%.

Florida, Texas, Nevada, and other no-tax states let you keep the full benefit of the federal preferential rates. A Florida resident pays only 15% plus 3.8% NIIT if applicable.

Our state capital gains tax rates guide has the exact rate for every state so you can calculate your true combined burden.

How to Calculate Tax on Different Asset Types

Different assets have different calculation rules. Here are the key variations.

Stocks and Bonds

Stock calculation is the simplest: proceeds minus cost basis equals gain. Your brokerage tracks your cost basis automatically for shares purchased after 2011 and reports it on Form 1099-B. Check that your brokerage's basis matches your records, especially for shares purchased before the mandatory tracking rules. Use our stock capital gains calculator for quick estimates.

Bond calculation works similarly, but there is an important distinction between interest income and capital gains. Interest from bonds is ordinary income, not a capital gain. A capital gain on bonds only occurs when you sell the bond for more than you paid. Our bonds tax guide explains this distinction.

Real Estate

Real estate calculations are more complex because of depreciation recapture. If you owned a rental property and claimed depreciation deductions, you must recapture those deductions at a 25% rate when you sell. The recapture amount is separate from the remaining capital gain, which is taxed at the regular long-term rate.

The calculation splits into two parts: depreciation recapture at 25% plus remaining gain at 0%, 15%, or 20%. Our real estate investment property tax guide walks through a complete rental property calculation.

Primary residence sales have a special exclusion. If you lived in the home for at least two of the five years before selling, you can exclude up to $250,000 of gain (single) or $500,000 (married). Our home sale tax guide explains the Section 121 exclusion rules.

Cryptocurrency

Crypto gains follow the same basic formula: sale proceeds minus cost basis equals gain. Every crypto transaction — selling, trading one coin for another, spending crypto on goods — is a taxable event. Our cryptocurrency tax guide covers which transactions are taxable and how to calculate the gain for each.

Mutual Funds and ETFs

Mutual fund calculations have an extra layer: capital gain distributions from the fund's own trading activity. These distributions are taxed as capital gains even though you did not sell your shares. You also have a gain or loss when you sell your shares, calculated the same way as for stocks. Our mutual funds and ETFs tax guide explains both types of taxation.

How Losses Change the Calculation

If you sell an asset for less than your cost basis, you have a capital loss. Losses offset gains, dollar for dollar, reducing your net taxable gain.

Short-term losses first offset short-term gains. Long-term losses first offset long-term gains. If your losses in one category exceed your gains in that category, the excess crosses over to offset gains in the other category.

If your total losses exceed your total gains, you can deduct up to $3,000 of the net loss against ordinary income each year. The remaining loss carries forward indefinitely to offset future gains. Our capital loss carryover guide explains how to track and use carryover losses across multiple years.

Tax loss harvesting is the strategy of intentionally selling losing positions to offset gains from your winners. Our tax loss harvesting guide covers the complete strategy including wash sale rule avoidance.

How to Report Your Calculated Gain on Your Tax Return

Once you have calculated your gain, reporting it on your tax return involves these forms:

Form 8949 lists every individual sale transaction. You report the sale date, purchase date, sale price, cost basis, and gain or loss for each transaction. Your brokerage provides Form 1099-B with most of this information pre-filled.

Schedule D summarizes all your Form 8949 entries and calculates your net capital gain or loss for the year. This is where the offsetting happens — gains and losses are netted together, and the $3,000 ordinary income deduction is claimed.

Form 1040, Line 7 carries your net capital gain from Schedule D to your main tax return.

Our step-by-step guide to reporting capital gains walks you through every form and line with detailed instructions.

If you have a large gain, you may need to make estimated tax payments to avoid underpayment penalties. Our estimated payments guide explains when you need to pay and how to calculate the amount.

5 Calculator Shortcuts That Save Time

1. Use Our Free Calculators

We built free calculators that do all the math instantly. Our short-term capital gains calculator handles ordinary income rate calculations. Our long-term capital gains calculator factors in the 0%/15%/20% brackets. Our stock calculator handles stock-specific calculations. Our real estate calculator includes depreciation recapture. And our crypto calculator covers cryptocurrency gains.

2. Check Your Brokerage's Basis Tracking

Since 2011, brokerages are required to track and report cost basis for covered securities. Check your 1099-B for the basis your brokerage reports, and compare it to your own records. Discrepancies are common, especially for shares acquired through dividend reinvestment or stock splits.

3. Use Tax Software Instead of Manual Calculation

Most tax software automatically calculates your capital gains tax when you input your 1099-B data. The software applies the correct rates, handles the income layering, and claims the $3,000 loss deduction. It is much faster and more accurate than manual calculation.

4. Keep a Running Calculation Throughout the Year

Do not wait until tax season to figure out your gains. Track every sale throughout the year so you know your tax situation in real time. This lets you harvest losses before December 31 and make estimated payments when needed.

5. Factor In Both Federal and State Rates

Most people calculate only their federal tax and forget the state portion. Your true combined rate is the federal rate plus your state rate plus the 3.8% NIIT if applicable. Check your combined rate using our state rates guide to avoid surprises at tax time.

Common Calculation Mistakes

Mistake 1: Not including selling expenses in the calculation. Broker commissions, real estate fees, and closing costs reduce your net proceeds. Skipping these overstates your gain and inflates your tax bill.

Mistake 2: Using the wrong cost basis method for mutual funds. If you own multiple purchases of the same fund, you must choose a cost basis method: FIFO, specific identification, or average cost. The method you choose can change your gain amount significantly. Our mutual funds guide explains each method.

Mistake 3: Forgetting the NIIT. High-income taxpayers who ignore the 3.8% surtax underestimate their total tax by thousands of dollars. Always check whether your income exceeds the NIIT threshold.

Mistake 4: Calculating tax on the full gain without accounting for losses. If you have both gains and losses, you must net them together before calculating tax. Calculating tax on each gain separately without offsetting losses overstates your tax.

Mistake 5: Confusing short-term and long-term gains. Applying the 15% long-term rate to a short-term gain results in a massive underpayment. Always verify your holding period before choosing a rate. Our holding period comparison guide explains the one-year threshold.

The Bottom Line

Calculating your capital gains tax correctly requires six steps: find your cost basis, calculate net proceeds, determine the gain, apply the correct rate, add the NIIT if applicable, and factor in state tax. Each step has details that can change your final number by hundreds or thousands of dollars.

The formula is simple — gain equals proceeds minus basis. But the rate application is where most mistakes happen. Your rate depends on your holding period, your total income, and whether the NIIT applies. Get any of these wrong and your calculation fails.

Use our calculators for quick estimates, but understand the steps so you can verify the numbers and plan your sales strategically. For more guides, calculators, and strategies, explore our full library of capital gains tax resources.

Fact-Checked & Reviewed

This article was written by Sarah Mitchell (CPA, MST (Master of Science in Taxation)) and reviewed for accuracy by David Chen (JD, LLM in Taxation (New York University)). All tax rates, thresholds, and rules referenced are based on IRS publications and current tax law as of the date published. Tax laws change frequently — always consult a qualified tax professional for advice specific to your situation.

calculate capital gains taxcapital gains tax formulacost basis calculationcapital gains tax ratesnet proceeds calculationtax rate bracketsstep by step tax calculation

Disclaimer: This article is for informational purposes only and does not constitute tax, legal, or financial advice. Tax laws and regulations change frequently, and the information presented here may not reflect the most current updates. You should consult with a qualified CPA, tax attorney, or financial advisor before making any tax-related decisions. TaxGainsCalc is not responsible for any actions taken based on the information provided in this article.