Short Term (Less than 1 year)
Long Term (More than 1 year)
Total Capital Gain:$0.00
Estimated Tax Rate:0%
Estimated Tax Owed:$0.00
Net Profit (After Tax):$0.00
function calculateCapitalGains() {
// Inputs
var purchasePrice = parseFloat(document.getElementById('cgAssetPurchasePrice').value);
var salePrice = parseFloat(document.getElementById('cgAssetSalePrice').value);
var annualIncome = parseFloat(document.getElementById('cgAnnualIncome').value);
var filingStatus = document.getElementById('cgTaxFilingStatus').value;
var duration = document.getElementById('cgOwnershipDuration').value;
// Validation
if (isNaN(purchasePrice) || isNaN(salePrice) || isNaN(annualIncome)) {
alert("Please enter valid numeric values for prices and income.");
return;
}
// Logic 1: Calculate Raw Gain
var capitalGain = salePrice – purchasePrice;
// Logic 2: Handle Loss
if (capitalGain 609350) taxRate = 0.37;
else if (annualIncome > 243725) taxRate = 0.35;
else if (annualIncome > 191950) taxRate = 0.32;
else if (annualIncome > 100525) taxRate = 0.24;
else if (annualIncome > 47150) taxRate = 0.22;
else if (annualIncome > 11600) taxRate = 0.12;
else taxRate = 0.10;
} else if (filingStatus === 'married') {
if (annualIncome > 731200) taxRate = 0.37;
else if (annualIncome > 487450) taxRate = 0.35;
else if (annualIncome > 383900) taxRate = 0.32;
else if (annualIncome > 201050) taxRate = 0.24;
else if (annualIncome > 94300) taxRate = 0.22;
else if (annualIncome > 23200) taxRate = 0.12;
else taxRate = 0.10;
} else { // Head of household
if (annualIncome > 609350) taxRate = 0.37;
else if (annualIncome > 243700) taxRate = 0.35;
else if (annualIncome > 191950) taxRate = 0.32;
else if (annualIncome > 100500) taxRate = 0.24;
else if (annualIncome > 63100) taxRate = 0.22;
else if (annualIncome > 16550) taxRate = 0.12;
else taxRate = 0.10;
}
} else {
// Long Term Capital Gains Rates (0%, 15%, 20%)
// Based on 2024 thresholds
if (filingStatus === 'single') {
if (annualIncome > 518900) taxRate = 0.20;
else if (annualIncome > 47025) taxRate = 0.15;
else taxRate = 0.0;
} else if (filingStatus === 'married') {
if (annualIncome > 583750) taxRate = 0.20;
else if (annualIncome > 94050) taxRate = 0.15;
else taxRate = 0.0;
} else { // Head of household
if (annualIncome > 551350) taxRate = 0.20;
else if (annualIncome > 63000) taxRate = 0.15;
else taxRate = 0.0;
}
}
// Logic 4: Net Investment Income Tax (NIIT) – The "Obamacare" Tax
// 3.8% surcharge if income exceeds thresholds ($200k Single, $250k Married)
var niitThreshold = (filingStatus === 'married') ? 250000 : 200000;
if (annualIncome > niitThreshold) {
// Technically applies to the lesser of NII or excess MAGI, simplified here as add-on for high earners
taxRate += 0.038;
}
// Calculation
var estimatedTax = capitalGain * taxRate;
var netProfit = capitalGain – estimatedTax;
// Formatting Output
var formatter = new Intl.NumberFormat('en-US', {
style: 'currency',
currency: 'USD',
});
document.getElementById('cgDisplayGain').innerText = formatter.format(capitalGain);
document.getElementById('cgDisplayRate').innerText = (taxRate * 100).toFixed(1) + "%";
document.getElementById('cgDisplayTax').innerText = formatter.format(estimatedTax);
document.getElementById('cgDisplayNet').innerText = formatter.format(netProfit);
document.getElementById('cgResults').style.display = 'block';
}
Understanding Capital Gains Tax on Your Investments
When you sell an asset—whether it's stocks, real estate, or a business—for more than you paid for it, the profit is known as a capital gain. The government taxes this profit, but the rate you pay depends heavily on how long you held the asset and your overall income level. This calculator helps investors estimate their potential tax liability for the 2024 tax year.
Short-Term vs. Long-Term Capital Gains
The single most important factor in calculating your tax is the duration of ownership:
Short-Term Capital Gains: Assets held for one year or less. These are taxed as "ordinary income," meaning they are added to your salary and taxed at your standard income tax bracket (ranging from 10% up to 37%).
Long-Term Capital Gains: Assets held for more than one year. These enjoy preferential tax treatment, with rates of 0%, 15%, or 20%, depending on your filing status and taxable income.
How the Tax Brackets Work
Unlike standard income tax, long-term capital gains brackets are much wider. For example, in 2024, a single filer can earn up to $47,025 and pay 0% in capital gains tax. The 15% rate applies to income between $47,026 and $518,900. Only those earning above $518,900 pay the top rate of 20%.
Note: High-income earners (typically above $200k for singles or $250k for married couples) may also be subject to an additional 3.8% Net Investment Income Tax (NIIT), which this calculator estimates in the final rate.
Strategies to Minimize Liability
Investors often use strategies like Tax-Loss Harvesting (selling losing investments to offset gains) or holding assets for at least one year and one day to qualify for long-term rates. Understanding your bracket before you sell is crucial for maximizing your net profit.