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
Frequently Asked Questions
What counts as a capital improvement?
Capital improvements add value, extend life, or adapt a property to new use. Examples: new roof, kitchen remodel, room addition, HVAC replacement, new windows. Repairs and maintenance (painting, fixing leaks) are not capital improvements.
Can I avoid capital gains tax by buying another property?
For your primary residence, you can use the $250,000/$500,000 exclusion every 2 years. For investment property, a 1031 exchange defers (not eliminates) capital gains by exchanging into a like-kind property within strict timelines.
How is the primary residence exclusion applied?
You must have owned and used the home as your primary residence for at least 2 of the 5 years before the sale. You can use the exclusion once every 2 years. Married couples filing jointly can exclude up to $500,000 if both meet the residency requirement.
Ready to run the numbers?
Open Capital Gains Tax Calculator