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_tax

Capital Gains Tax

capital_gains_tax = cap_gains_tax

Depreciation Recapture Tax

dep_recapture_tax = depreciation_tax

Total Gain

gain = total_gain

Taxable Gain (after exclusion)

taxable = taxable_gain

Adjusted Cost Basis

basis = adjusted_basis

Variables

VariableDescriptionDefault
sale_priceSale Price(USD)550000
purchase_priceOriginal Purchase Price(USD)350000
improvementsCapital Improvements(USD)40000
selling_costsSelling Costs (commissions, etc.)(USD)33000
depreciation_recaptureAccumulated Depreciation (investment property)(USD)0
exclusionPrimary Residence Exclusion(USD)250000
ltcg_rateLong-Term Capital Gains Rate(%)15
depreciation_rateDepreciation Recapture Rate(%)25
adjusted_basisDerived value= purchase_price + improvementscalculated
net_saleDerived value= sale_price - selling_costscalculated
total_gainDerived value= net_sale - adjusted_basis + depreciation_recapturecalculated
taxable_gainDerived value= total_gain - exclusion > 0 ? total_gain - exclusion : 0calculated
depreciation_taxDerived value= depreciation_recapture * depreciation_rate / 100calculated
cap_gains_taxDerived value= taxable_gain * ltcg_rate / 100calculated

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:

  • Single: Exclude up to $250,000 of gain
  • Married filing jointly: Exclude up to $500,000
  • Depreciation Recapture

    On investment properties, depreciation taken is recaptured at 25%, separate from the capital gains rate.

    Tax Rates

  • Short-term (held < 1 year): Ordinary income rates (up to 37%)
  • Long-term (held > 1 year): 0%, 15%, or 20% depending on income
  • 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.

    sale_price = 550000purchase_price = 350000improvements = 40000selling_costs = 33000depreciation_recapture = 0exclusion = 250000ltcg_rate = 15depreciation_rate = 25
    1. 01Adjusted basis: $350,000 + $40,000 = $390,000
    2. 02Net sale proceeds: $550,000 - $33,000 = $517,000
    3. 03Total gain: $517,000 - $390,000 = $127,000
    4. 04Taxable gain after exclusion: $127,000 - $250,000 = $0 (fully excluded)
    5. 05Capital gains tax: $0
    6. 06Total tax owed: $0

    Ready to run the numbers?

    Open Capital Gains Tax Calculator