Less than 1 Year (Short-Term)
More than 1 Year (Long-Term)
Total Capital Gain:$0.00
Estimated Federal Tax Rate:0%
Net Investment Income Tax (NIIT):$0.00
Estimated Tax Owed:$0.00
After-Tax Profit:$0.00
Understanding Your Capital Gains Tax Liability
Calculating your capital gains tax is a crucial step in financial planning, whether you are selling stocks, real estate, or other investment assets. This calculator provides an estimate of your federal tax liability based on the 2024 tax code specifications for both short-term and long-term assets.
Short-Term vs. Long-Term Capital Gains
The duration for which you hold an asset significantly impacts your tax rate:
Short-Term Capital Gains: Assets held for one year or less. These are taxed as ordinary income, meaning they are subject to your standard federal income tax bracket, which can range from 10% up to 37%.
Long-Term Capital Gains: Assets held for more than one year. These benefit from preferential tax rates of 0%, 15%, or 20%, depending on your taxable income and filing status.
Pro Tip: Holding an asset for at least one year and one day can significantly reduce your tax bill by shifting the gain from an ordinary income rate (e.g., 32%) to a long-term capital gains rate (e.g., 15%).
2024 Long-Term Capital Gains Tax Brackets
For the 2024 tax year, the long-term capital gains tax rates are determined by your taxable income thresholds:
For Single Filers:
0% Rate: Income up to $47,025
15% Rate: Income between $47,026 and $518,900
20% Rate: Income over $518,900
For Married Filing Jointly:
0% Rate: Income up to $94,050
15% Rate: Income between $94,051 and $583,750
20% Rate: Income over $583,750
Net Investment Income Tax (NIIT)
High-income earners may be subject to an additional 3.8% Net Investment Income Tax. This applies if your Modified Adjusted Gross Income (MAGI) exceeds:
$200,000 for Single or Head of Household filers
$250,000 for Married Filing Jointly
This calculator automatically checks if your income qualifies for NIIT and adds it to your total estimated tax.
How to Calculate Your Cost Basis
Your "Cost Basis" is generally the purchase price of the asset plus any costs associated with the purchase (like commissions or recording fees). For real estate, you can also add the cost of capital improvements made to the property. Your Capital Gain is simply the Sale Price minus the Cost Basis.
function calculateCapitalGains() {
// 1. Get Inputs
var purchasePrice = parseFloat(document.getElementById('cgt_purchase_price').value);
var salePrice = parseFloat(document.getElementById('cgt_sale_price').value);
var income = parseFloat(document.getElementById('cgt_income').value);
var filingStatus = document.getElementById('cgt_filing_status').value;
var duration = document.getElementById('cgt_duration').value;
// 2. Validation
if (isNaN(purchasePrice) || isNaN(salePrice) || isNaN(income)) {
alert("Please enter valid numbers for prices and income.");
return;
}
// 3. Calculate Gross Gain
var gain = salePrice – purchasePrice;
// Handle Loss
if (gain <= 0) {
document.getElementById('cgt_result').style.display = 'block';
document.getElementById('res_gain').innerHTML = formatCurrency(gain);
document.getElementById('res_rate').innerHTML = "0%";
document.getElementById('res_niit').innerHTML = "$0.00";
document.getElementById('res_tax').innerHTML = "$0.00";
document.getElementById('res_profit').innerHTML = formatCurrency(gain); // Loss is the profit (negative)
return;
}
var taxRate = 0;
var taxAmount = 0;
var niitAmount = 0;
// 4. Determine Tax Logic
if (duration === 'short') {
// Short Term: Taxed as Ordinary Income
// Simplified estimate using 2024 Marginal Brackets based on total income (Income + Gain)
// Note: This is a marginal estimate. A full calculator would integrate over brackets.
var totalIncome = income + gain;
taxRate = getMarginalTaxRate(totalIncome, filingStatus);
taxAmount = gain * taxRate;
} else {
// Long Term: 0%, 15%, 20% buckets
// Thresholds 2024
var limit0, limit15;
if (filingStatus === 'single') {
limit0 = 47025;
limit15 = 518900;
} else if (filingStatus === 'married_joint') {
limit0 = 94050;
limit15 = 583750;
} else { // Head of household
limit0 = 63000;
limit15 = 551350;
}
// Determine rate based on income
// The logic: The gain stacks on top of ordinary income.
// Simplified: We determine the rate applicable to the gain based on where the income sits.
if (income < limit0) {
// Some gain might be 0%, some might push into 15%
var roomIn0 = limit0 – income;
if (gain limit15) {
var gainAt20 = totalIncome – limit15;
var gainAt15 = remainder – gainAt20;
taxAmount = (gainAt15 * 0.15) + (gainAt20 * 0.20);
// weighted average rate for display
taxRate = taxAmount / gain;
} else {
taxAmount = remainder * 0.15;
taxRate = taxAmount / gain;
}
}
} else if (income >= limit0 && income < limit15) {
// Starts at 15%
var roomIn15 = limit15 – income;
if (gain niitThreshold) {
// NIIT is 3.8% of the lesser of: Gain OR (MAGI – Threshold)
var amountSubjectToNiit = Math.min(gain, magi – niitThreshold);
niitAmount = amountSubjectToNiit * 0.038;
}
var totalTax = taxAmount + niitAmount;
var netProfit = gain – totalTax;
// 6. Display Results
document.getElementById('cgt_result').style.display = 'block';
document.getElementById('res_gain').innerHTML = formatCurrency(gain);
// Display rate as percentage (Total Tax / Gain) * 100 for effective rate
var effectiveRate = (gain > 0) ? (totalTax / gain) * 100 : 0;
document.getElementById('res_rate').innerHTML = effectiveRate.toFixed(2) + "% (Effective)";
document.getElementById('res_niit').innerHTML = formatCurrency(niitAmount);
document.getElementById('res_tax').innerHTML = formatCurrency(totalTax);
document.getElementById('res_profit').innerHTML = formatCurrency(netProfit);
}
function getMarginalTaxRate(totalIncome, status) {
// Simplified 2024 Federal Tax Brackets for estimation
// This returns the top marginal bracket the income falls into
// Real tax calculation would need to integrate across brackets, but this is standard for 'estimated rate' inputs
if (status === 'single') {
if (totalIncome > 609350) return 0.37;
if (totalIncome > 243725) return 0.35;
if (totalIncome > 191950) return 0.32;
if (totalIncome > 100525) return 0.24;
if (totalIncome > 47150) return 0.22;
if (totalIncome > 11600) return 0.12;
return 0.10;
} else if (status === 'married_joint') {
if (totalIncome > 731200) return 0.37;
if (totalIncome > 487450) return 0.35;
if (totalIncome > 383900) return 0.32;
if (totalIncome > 201050) return 0.24;
if (totalIncome > 94300) return 0.22;
if (totalIncome > 23200) return 0.12;
return 0.10;
} else { // Head of household
if (totalIncome > 609350) return 0.37;
if (totalIncome > 243700) return 0.35;
if (totalIncome > 191950) return 0.32;
if (totalIncome > 100500) return 0.24;
if (totalIncome > 63100) return 0.22;
if (totalIncome > 16550) return 0.12;
return 0.10;
}
}
function formatCurrency(num) {
return '$' + num.toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,');
}