CalcMaven
How to Calculate

How to Calculate Capital Gains Tax (Step-by-Step 2025 Guide)

By Alex B.|Updated March 5, 2026|9 min read

For informational purposes only, not financial advice. Full disclaimer

Calculating capital gains tax requires three pieces of information: your cost basis, your sale price, and your holding period. The formula itself is straightforward, but several rules around cost basis adjustments, wash sales, and netting gains against losses add complexity. This guide walks through each step with worked examples for stocks, real estate, and cryptocurrency.

Skip the Math

Enter your sale price, cost basis, holding period, income, and filing status to get your exact capital gains tax in seconds.

Use the Capital Gains Tax Calculator

The Capital Gains Tax Formula

Capital Gain (or Loss) = Net Sale Proceeds - Adjusted Cost Basis

Net sale proceeds are the amount you receive after subtracting selling costs (broker commissions, transfer fees, closing costs for real estate). Adjusted cost basis is your original purchase price plus any acquisition costs, reinvested dividends, and capital improvements, minus any depreciation claimed.

  1. Determine your adjusted cost basis (purchase price + acquisition costs + improvements - depreciation)
  2. Calculate net sale proceeds (sale price - selling costs)
  3. Subtract cost basis from sale proceeds to find the gain or loss
  4. Classify the gain as short-term (held 1 year or less) or long-term (held more than 1 year)
  5. Apply the correct tax rate based on your taxable income and filing status

Step 1: Determine Your Cost Basis

Cost basis is the foundation of every capital gains calculation. Getting it wrong means paying too much or too little tax. The basic cost basis is your purchase price, but several adjustments can increase or decrease it.

Cost Basis Adjustments That Increase Basis

  • Purchase commissions and fees
  • Reinvested dividends and capital gains distributions (mutual funds)
  • Capital improvements (real estate): new roof, kitchen renovation, additions
  • Transfer taxes and recording fees
  • Legal fees related to acquisition

Cost Basis Adjustments That Decrease Basis

  • Depreciation deductions claimed (rental property)
  • Return of capital distributions
  • Insurance reimbursements for casualty losses
  • Easements granted on real property

For stocks purchased at multiple prices (dollar-cost averaging), you can use specific identification to choose which shares to sell, or default to FIFO (first in, first out). Specific identification is almost always better because it lets you control whether a sale generates a short-term or long-term gain and how large that gain is.

When I sold a portion of my index fund holdings, switching from FIFO to specific identification saved me about $800 in taxes. I selected the highest-cost-basis shares, which minimized the taxable gain. Most brokerage platforms let you choose your cost basis method in account settings.

Alex B.

Step 2: Calculate Net Sale Proceeds

Net sale proceeds equal the gross sale price minus any costs of selling. For stocks, this includes broker commissions (though many brokers now charge $0). For real estate, subtract agent commissions (typically 5-6% of sale price), transfer taxes, title insurance, and closing costs.

Example Calculation

You sell a rental property for $350,000. Selling costs include a 5% agent commission ($17,500), $2,000 in closing costs, and $1,200 in transfer taxes.

  1. Gross sale price: $350,000
  2. Agent commission: -$17,500
  3. Closing costs: -$2,000
  4. Transfer taxes: -$1,200
  5. Net sale proceeds: $350,000 - $20,700 = $329,300

Your net sale proceeds are $329,300. This is the figure you subtract your cost basis from to determine the gain.

Step 3: Calculate the Gain and Classify It

Subtract your adjusted cost basis from net sale proceeds. If the result is positive, you have a capital gain. If negative, you have a capital loss. Then check the holding period: did you hold the asset for more than one year? If yes, it qualifies for long-term rates.

Example Calculation

Continuing the rental property example: you purchased it for $250,000, spent $30,000 on improvements, and claimed $40,000 in depreciation over 5 years.

  1. Original cost: $250,000
  2. Plus improvements: +$30,000
  3. Minus depreciation: -$40,000
  4. Adjusted cost basis: $240,000
  5. Net sale proceeds: $329,300 (from Step 2)
  6. Capital gain: $329,300 - $240,000 = $89,300
  7. Holding period: 5 years (long-term)

You have a long-term capital gain of $89,300. Note: the $40,000 in depreciation recapture is taxed at a flat 25% rate ($10,000), and the remaining $49,300 is taxed at your long-term capital gains rate.

Step 4: Apply the Correct Tax Rate

Short-term gains are added to your ordinary income and taxed at your marginal tax bracket (10% to 37%). Long-term gains are taxed at preferential rates of 0%, 15%, or 20% based on your total taxable income. The gain itself can push you into a higher bracket, so the calculation requires stacking the gain on top of your other income.

Example Calculation

Single filer, $60,000 salary, standard deduction of $15,000, and a $20,000 long-term capital gain in 2025.

  1. Ordinary taxable income: $60,000 - $15,000 = $45,000
  2. Total taxable income (with gain): $45,000 + $20,000 = $65,000
  3. First $48,350 of the gain is in the 0% bracket: $48,350 - $45,000 = $3,350 at 0%
  4. Remaining gain: $20,000 - $3,350 = $16,650 at 15%
  5. Capital gains tax: ($3,350 x 0%) + ($16,650 x 15%) = $0 + $2,497.50

Total capital gains tax: $2,497.50. Notice that part of the gain falls in the 0% bracket because your ordinary income was below the $48,350 threshold.

The Wash Sale Rule

The wash sale rule (IRS Section 1091) prevents you from claiming a capital loss if you repurchase the same or a "substantially identical" security within 30 days before or after the sale. The disallowed loss is added to the cost basis of the replacement shares, deferring (not eliminating) the tax benefit.

  • The 30-day window applies in both directions: 30 days before and 30 days after the sale (61-day total window)
  • "Substantially identical" includes the same stock/ETF, options on the same stock, and similar index funds from different providers
  • The rule applies across all your accounts (brokerage, IRA, spouse's accounts)
  • Wash sales on the final sale of a position in an IRA may result in a permanent loss of the deduction
Wash Sale Workaround

To harvest a loss without triggering a wash sale, sell the position and wait 31 days before repurchasing, or immediately buy a similar (but not substantially identical) security. For example, sell an S&P 500 ETF and buy a total stock market ETF.

Tax-Loss Harvesting: Offsetting Gains With Losses

Tax-loss harvesting is the strategy of selling investments at a loss to offset capital gains. Short-term losses first offset short-term gains (taxed at up to 37%), then long-term gains. Long-term losses first offset long-term gains, then short-term gains. After netting all gains and losses, if you have a net loss, you can deduct up to $3,000 against ordinary income per year.

According to a Vanguard study, systematic tax-loss harvesting adds roughly 0.50 to 1.50 percentage points of after-tax return per year for taxable portfolios over $500,000. The benefit compounds significantly over decades.

Example Calculation

You have $10,000 in short-term gains, $5,000 in long-term gains, and $8,000 in long-term losses during the year.

  1. Long-term gains net against long-term losses first: $5,000 - $8,000 = -$3,000 net long-term loss
  2. Net long-term loss offsets short-term gains: $10,000 - $3,000 = $7,000 net short-term gain
  3. Tax on $7,000 short-term gain at 24% bracket: $1,680

Without tax-loss harvesting, you would owe tax on the full $15,000 in gains. By realizing $8,000 in losses, you reduced your taxable gain to $7,000, saving approximately $1,920 in taxes.

Calculating Capital Gains on Crypto

Cryptocurrency gains are calculated the same way as stock gains: sale price minus cost basis. The complexity arises from frequent trading, token swaps, staking rewards, and airdrops. Each swap between cryptocurrencies (e.g., BTC to ETH) is a taxable event requiring separate cost basis tracking.

  • Staking rewards and mining income are taxed as ordinary income at fair market value when received, then subject to capital gains tax when sold
  • Airdrops are taxed as ordinary income at receipt and capital gains at sale
  • Moving crypto between your own wallets is not a taxable event
  • Gas fees (transaction costs) can be added to cost basis or deducted from sale proceeds

Special Rules: Depreciation Recapture and Collectibles

Depreciation recapture on real estate: when you sell a rental property, any depreciation you previously deducted is "recaptured" and taxed at a flat 25% rate (Section 1250 recapture). This applies regardless of your income level and is separate from the long-term capital gains rate on the remaining profit.

Collectibles (art, antiques, coins, precious metals, stamps) held for more than one year are taxed at a maximum rate of 28%, not the standard 0%/15%/20% long-term rates. This higher rate also applies to gains from qualified small business stock (Section 1202) that exceeds the exclusion amount.

Bottom Line

The core calculation is simple: subtract cost basis from sale proceeds and apply the right rate. But the details matter. Correctly tracking cost basis, understanding the wash sale rule, and strategically harvesting losses can save thousands of dollars over an investing lifetime. Use our capital gains tax calculator to run your numbers and compare short-term vs long-term scenarios.

Frequently Asked Questions

How do I calculate capital gains tax on stocks?+
Subtract your total cost basis (purchase price + commissions) from your net sale proceeds (sale price - commissions). If you held the stock for more than one year, apply long-term rates (0%, 15%, or 20% based on income). If one year or less, add the gain to your ordinary income and apply your marginal tax rate (10-37%).
What is adjusted cost basis?+
Adjusted cost basis is your original purchase price modified by certain additions (commissions, reinvested dividends, capital improvements) and subtractions (depreciation, return of capital). For rental property, your basis decreases by the depreciation deductions you claim each year, which affects the gain calculation when you sell.
Do I owe capital gains tax if I reinvest the proceeds?+
Yes. Reinvesting sale proceeds does not defer or eliminate capital gains tax (unlike a 1031 exchange for real estate). When you sell a stock at a profit and immediately buy another stock, you owe tax on the gain from the sale. The new purchase simply establishes a new cost basis for future calculations.
What is the wash sale rule?+
The wash sale rule (IRS Section 1091) disallows a capital loss deduction if you purchase the same or substantially identical security within 30 days before or after the sale. The disallowed loss gets added to the cost basis of the replacement shares, so it is deferred rather than lost. The rule applies across all your accounts, including IRAs.
How does tax-loss harvesting work?+
Tax-loss harvesting involves selling investments at a loss to offset capital gains and reduce your tax bill. Losses first offset gains of the same type (short-term losses against short-term gains). Net losses exceeding your gains can deduct up to $3,000 from ordinary income per year, with unlimited carryforward to future years.
Are there capital gains on inherited property?+
Inherited assets receive a "stepped-up" cost basis equal to the fair market value at the date of death. If you inherit stock worth $100,000 (originally purchased for $20,000), your cost basis is $100,000. If you sell immediately at $100,000, your capital gain is $0. This stepped-up basis effectively eliminates tax on gains that occurred during the decedent's lifetime.
Do I need to pay estimated taxes on capital gains?+
If you expect to owe $1,000 or more in tax beyond what is withheld from wages, the IRS requires quarterly estimated tax payments (Form 1040-ES). Large capital gains from a sale mid-year should be estimated and paid in the quarter the sale occurred. Underpayment can result in penalties, though safe harbor rules (paying 100% of prior year tax, or 110% for high earners) provide protection.

Related Calculators

Disclaimer: This article is for informational purposes only and does not constitute financial advice. Consult a qualified financial advisor for decisions about your specific situation.

How to Calculate Capital Gains Tax (2025) | CalcMaven