Short Term (Less than 1 year)
Long Term (More than 1 year)
Total Capital Gain:$0.00
Tax Classification:Short Term
Applicable Tax Rate (Est.):0%
Estimated Tax Owed:$0.00
Net Profit After Tax:$0.00
function calculateCapitalGains() {
// 1. Get Elements
var purchaseInput = document.getElementById('cgtPurchasePrice');
var saleInput = document.getElementById('cgtSalePrice');
var incomeInput = document.getElementById('cgtAnnualIncome');
var statusSelect = document.getElementById('cgtFilingStatus');
var durationSelect = document.getElementById('cgtDuration');
var resultBox = document.getElementById('cgtResultBox');
// 2. Parse Values
var purchasePrice = parseFloat(purchaseInput.value);
var salePrice = parseFloat(saleInput.value);
var annualIncome = parseFloat(incomeInput.value);
var filingStatus = statusSelect.value;
var duration = durationSelect.value;
// 3. Validation
if (isNaN(purchasePrice) || isNaN(salePrice) || isNaN(annualIncome)) {
alert("Please enter valid numeric values for all fields.");
return;
}
// 4. Calculate Raw Gain
var capitalGain = salePrice – purchasePrice;
// 5. Initialize Tax Variables
var taxRate = 0;
var taxAmount = 0;
var taxTypeDisplay = "";
// 6. Logic
if (capitalGain <= 0) {
// Loss or Break-even
taxAmount = 0;
taxRate = 0;
taxTypeDisplay = "Capital Loss / None";
} else {
if (duration === "short") {
// Short Term Capital Gains (Taxed as Ordinary Income)
taxTypeDisplay = "Short Term (Ordinary Income)";
// Simplified Marginal Tax Rate Estimation (2024 Brackets – Simplified)
// We use the bracket where (Income + Gain) falls to estimate the hit on the gain.
var totalIncome = annualIncome + capitalGain;
// Single Logic (Simplified 2024)
if (filingStatus === "single") {
if (totalIncome <= 11600) taxRate = 0.10;
else if (totalIncome <= 47150) taxRate = 0.12;
else if (totalIncome <= 100525) taxRate = 0.22;
else if (totalIncome <= 191950) taxRate = 0.24;
else if (totalIncome <= 243725) taxRate = 0.32;
else if (totalIncome <= 609350) taxRate = 0.35;
else taxRate = 0.37;
}
// Married Joint Logic (Simplified 2024)
else if (filingStatus === "married") {
if (totalIncome <= 23200) taxRate = 0.10;
else if (totalIncome <= 94300) taxRate = 0.12;
else if (totalIncome <= 201050) taxRate = 0.22;
else if (totalIncome <= 383900) taxRate = 0.24;
else if (totalIncome <= 487450) taxRate = 0.32;
else if (totalIncome <= 731200) taxRate = 0.35;
else taxRate = 0.37;
}
// Head of Household Logic (Simplified 2024)
else {
if (totalIncome <= 16550) taxRate = 0.10;
else if (totalIncome <= 63100) taxRate = 0.12;
else if (totalIncome <= 100500) taxRate = 0.22;
else if (totalIncome <= 191950) taxRate = 0.24;
else if (totalIncome <= 243700) taxRate = 0.32;
else if (totalIncome <= 609350) taxRate = 0.35;
else taxRate = 0.37;
}
taxAmount = capitalGain * taxRate;
} else {
// Long Term Capital Gains (0%, 15%, 20%)
taxTypeDisplay = "Long Term (Preferential Rates)";
// Logic based on Taxable Income (2024 Thresholds)
// Note: LTCG rate is based on taxable income, not just the gain.
if (filingStatus === "single") {
if (annualIncome <= 47025) taxRate = 0.00;
else if (annualIncome <= 518900) taxRate = 0.15;
else taxRate = 0.20;
}
else if (filingStatus === "married") {
if (annualIncome <= 94050) taxRate = 0.00;
else if (annualIncome <= 583750) taxRate = 0.15;
else taxRate = 0.20;
}
else { // Head of Household
if (annualIncome <= 63000) taxRate = 0.00;
else if (annualIncome <= 551350) taxRate = 0.15;
else taxRate = 0.20;
}
taxAmount = capitalGain * taxRate;
// Note: Net Investment Income Tax (NIIT) of 3.8% logic could be added for high earners,
// but kept simple here for standard implementation.
}
}
var netProfit = capitalGain – taxAmount;
// 7. Display Results
document.getElementById('resTotalGain').innerText = "$" + capitalGain.toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2});
document.getElementById('resTaxType').innerText = taxTypeDisplay;
document.getElementById('resTaxRate').innerText = (taxRate * 100).toFixed(1) + "%";
document.getElementById('resTaxAmount').innerText = "$" + taxAmount.toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2});
document.getElementById('resNetProfit').innerText = "$" + netProfit.toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2});
resultBox.style.display = "block";
}
Understanding Capital Gains Tax
Calculating your potential tax liability on investments is crucial for effective financial planning. Whether you are selling real estate, stocks, or cryptocurrency, the profit you make—known as the "capital gain"—is subject to federal taxation. This Capital Gains Tax Calculator helps you estimate your tax bill based on the 2024/2025 tax brackets and your filing status.
How Capital Gains Are Calculated
The calculation starts with determining your basis (usually the purchase price plus any improvements or fees) and subtracting it from the sale price. The remaining amount is your capital gain.
For example, if you bought a stock portfolio for $50,000 and sold it for $75,000, your gross capital gain is $25,000. However, the tax rate applied to this $25,000 depends heavily on how long you held the asset.
Short-Term vs. Long-Term Capital Gains
The duration of asset ownership determines your tax rate classification:
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 wages and taxed at your regular marginal tax rate (ranging from 10% 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 income level. This lower rate is designed to encourage long-term investment.
2024 Long-Term Capital Gains Tax Brackets
Unlike ordinary income, long-term gains are taxed at fixed thresholds. Below are the income thresholds for the 2024 tax year:
Tax Rate
Single Filers
Married Filing Jointly
Head of Household
0%
Up to $47,025
Up to $94,050
Up to $63,000
15%
$47,026 – $518,900
$94,051 – $583,750
$63,001 – $551,350
20%
Over $518,900
Over $583,750
Over $551,350
Strategies to Minimize Capital Gains Tax
Hold for over a year: The simplest way to reduce your tax bill is to wait until the asset qualifies for long-term status.
Tax-Loss Harvesting: You can offset capital gains by selling underperforming assets at a loss. These losses can reduce your taxable gains dollar-for-dollar.
Use Tax-Advantaged Accounts: Investments held in 401(k)s or IRAs grow tax-deferred or tax-free, avoiding immediate capital gains taxes upon sale within the account.
Frequently Asked Questions
Does this calculator include the Net Investment Income Tax (NIIT)?
This calculator provides a baseline estimate using standard brackets. High-income earners (typically above $200,000 for singles or $250,000 for married couples) may be subject to an additional 3.8% Net Investment Income Tax surtax on top of the rates calculated above.
How does my annual income affect the calculation?
Your annual taxable income determines which tax bracket you fall into. For short-term gains, it determines your marginal rate. For long-term gains, it determines whether you pay 0%, 15%, or 20% on the profit.