Capital Gains Tax Calculator Formula
Understand the math behind the capital gains tax calculator. Each variable explained with a worked example.
Formulas Used
Total Estimated Tax
total_tax = cap_gains_tax + depreciation_taxCapital Gains Tax
capital_gains_tax = cap_gains_taxDepreciation Recapture Tax
dep_recapture_tax = depreciation_taxTotal Gain
gain = total_gainTaxable Gain (after exclusion)
taxable = taxable_gainAdjusted Cost Basis
basis = adjusted_basisVariables
| Variable | Description | Default |
|---|---|---|
sale_price | Sale Price(USD) | 550000 |
purchase_price | Original Purchase Price(USD) | 350000 |
improvements | Capital Improvements(USD) | 40000 |
selling_costs | Selling Costs (commissions, etc.)(USD) | 33000 |
depreciation_recapture | Accumulated Depreciation (investment property)(USD) | 0 |
exclusion | Primary Residence Exclusion(USD) | 250000 |
ltcg_rate | Long-Term Capital Gains Rate(%) | 15 |
depreciation_rate | Depreciation Recapture Rate(%) | 25 |
adjusted_basis | Derived value= purchase_price + improvements | calculated |
net_sale | Derived value= sale_price - selling_costs | calculated |
total_gain | Derived value= net_sale - adjusted_basis + depreciation_recapture | calculated |
taxable_gain | Derived value= total_gain - exclusion > 0 ? total_gain - exclusion : 0 | calculated |
depreciation_tax | Derived value= depreciation_recapture * depreciation_rate / 100 | calculated |
cap_gains_tax | Derived value= taxable_gain * ltcg_rate / 100 | calculated |
How It Works
Capital Gains Tax on Real Estate
When you sell property for more than your adjusted basis, you owe capital gains tax on the profit.
Adjusted Basis
Basis = Purchase Price + Capital Improvements - Depreciation Taken
Computing the Gain
Gain = (Sale Price - Selling Costs) - Adjusted Basis
Primary Residence Exclusion
If you lived in the home at least 2 of the last 5 years:
Depreciation Recapture
On investment properties, depreciation taken is recaptured at 25%, separate from the capital gains rate.
Tax Rates
Worked Example
Selling a primary residence for $550,000. Purchased at $350,000 with $40,000 in improvements. Selling costs $33,000. Single filer with $250,000 exclusion.
- 01Adjusted basis: $350,000 + $40,000 = $390,000
- 02Net sale proceeds: $550,000 - $33,000 = $517,000
- 03Total gain: $517,000 - $390,000 = $127,000
- 04Taxable gain after exclusion: $127,000 - $250,000 = $0 (fully excluded)
- 05Capital gains tax: $0
- 06Total tax owed: $0
Ready to run the numbers?
Open Capital Gains Tax Calculator