Capital Gains Tax Calculator Formula

Understand the math behind the capital gains tax calculator. Each variable explained with a worked example.

Formulas Used

Capital Gain

capital_gain = gain

Tax on Gain

tax_owed = gain * holding_period / 100

After-Tax Profit

net_profit = gain * (1 - holding_period / 100)

Total Return

total_return = purchase_price > 0 ? gain / purchase_price * 100 : 0

Variables

VariableDescriptionDefault
purchase_pricePurchase Price(USD)10000
sale_priceSale Price(USD)15000
holding_periodHolding Period15
gainDerived value= max(sale_price - purchase_price, 0)calculated

How It Works

Capital Gains Tax Rates (2024)

Long-Term (held >1 year)

| Income Level | Rate | |---|---| | Up to ~$47,025 (single) | 0% | | $47,026-$518,900 | 15% | | Over $518,900 | 20% |

Short-Term (<1 year)

Taxed as ordinary income at your marginal tax rate (up to 37%).

Worked Example

Bought at $10,000, sold at $15,000, held over 1 year.

purchase_price = 10000sale_price = 15000holding_period = 15
  1. 01Capital gain = $15,000 - $10,000 = $5,000
  2. 02Tax at 15% = $5,000 x 0.15 = $750
  3. 03Net profit = $5,000 - $750 = $4,250

Ready to run the numbers?

Open Capital Gains Tax Calculator