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 LevelRate Up to ~$47,025 (single)0% $47,026-$518,90015% Over $518,90020%

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

Frequently Asked Questions

What is the difference between short-term and long-term gains?

Short-term gains (held under 1 year) are taxed as ordinary income. Long-term gains (held over 1 year) get preferential rates of 0%, 15%, or 20%.

Can capital losses offset gains?

Yes. Capital losses offset capital gains dollar-for-dollar. If losses exceed gains, you can deduct up to $3,000 against ordinary income per year.

Do I owe tax on unrealized gains?

No. Capital gains tax is only owed when you sell an asset. Unrealized gains (paper profits) are not taxed until the sale occurs.

Ready to run the numbers?

Open Capital Gains Tax Calculator