How to Calculate Capital Gains Tax (Step-by-Step 2025 Guide)
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.
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 CalculatorThe Capital Gains Tax Formula
Capital Gain (or Loss) = Net Sale Proceeds - Adjusted Cost BasisNet 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.
- Determine your adjusted cost basis (purchase price + acquisition costs + improvements - depreciation)
- Calculate net sale proceeds (sale price - selling costs)
- Subtract cost basis from sale proceeds to find the gain or loss
- Classify the gain as short-term (held 1 year or less) or long-term (held more than 1 year)
- 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.
- Gross sale price: $350,000
- Agent commission: -$17,500
- Closing costs: -$2,000
- Transfer taxes: -$1,200
- 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.
- Original cost: $250,000
- Plus improvements: +$30,000
- Minus depreciation: -$40,000
- Adjusted cost basis: $240,000
- Net sale proceeds: $329,300 (from Step 2)
- Capital gain: $329,300 - $240,000 = $89,300
- 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.
- Ordinary taxable income: $60,000 - $15,000 = $45,000
- Total taxable income (with gain): $45,000 + $20,000 = $65,000
- First $48,350 of the gain is in the 0% bracket: $48,350 - $45,000 = $3,350 at 0%
- Remaining gain: $20,000 - $3,350 = $16,650 at 15%
- 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
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.
- Long-term gains net against long-term losses first: $5,000 - $8,000 = -$3,000 net long-term loss
- Net long-term loss offsets short-term gains: $10,000 - $3,000 = $7,000 net short-term gain
- 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?+
What is adjusted cost basis?+
Do I owe capital gains tax if I reinvest the proceeds?+
What is the wash sale rule?+
How does tax-loss harvesting work?+
Are there capital gains on inherited property?+
Do I need to pay estimated taxes on capital gains?+
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.