Short Term (Less than 1 year)
Long Term (More than 1 year)
Total Capital Gain:$0.00
Estimated Federal Tax Rate:0%
Est. Federal Tax Amount:$0.00
Net Investment Income Tax (NIIT):$0.00
Net Profit After Taxes:$0.00
*Estimates based on 2024 federal tax brackets. Does not include state taxes.
function calculateCapitalGains() {
// Get Input Values
var purchase = parseFloat(document.getElementById('purchasePrice').value);
var sale = parseFloat(document.getElementById('salePrice').value);
var income = parseFloat(document.getElementById('annualIncome').value);
var status = document.getElementById('filingStatus').value;
var duration = document.getElementById('ownershipDuration').value;
// Validation
if (isNaN(purchase) || isNaN(sale) || isNaN(income)) {
alert("Please enter valid numbers for prices and income.");
return;
}
var gain = sale – purchase;
var taxRate = 0;
var taxAmount = 0;
var niit = 0;
// Logic for Negative Gain (Loss)
if (gain 609350) taxRate = 0.37;
else if (totalIncome > 243725) taxRate = 0.35;
else if (totalIncome > 191950) taxRate = 0.32;
else if (totalIncome > 100525) taxRate = 0.24;
else if (totalIncome > 47150) taxRate = 0.22;
else if (totalIncome > 11600) taxRate = 0.12;
else taxRate = 0.10;
} else if (status === 'married') {
if (totalIncome > 731200) taxRate = 0.37;
else if (totalIncome > 487450) taxRate = 0.35;
else if (totalIncome > 383900) taxRate = 0.32;
else if (totalIncome > 201050) taxRate = 0.24;
else if (totalIncome > 94300) taxRate = 0.22;
else if (totalIncome > 23200) taxRate = 0.12;
else taxRate = 0.10;
} else { // Head of Household
if (totalIncome > 609350) taxRate = 0.37;
else if (totalIncome > 243700) taxRate = 0.35;
else if (totalIncome > 191950) taxRate = 0.32;
else if (totalIncome > 100500) taxRate = 0.24;
else if (totalIncome > 63100) taxRate = 0.22;
else if (totalIncome > 16550) taxRate = 0.12;
else taxRate = 0.10;
}
}
// Logic for Long Term (Capital Gains Rates 0%, 15%, 20%)
else {
// Thresholds based on 2024 tax year approx
var limit0, limit15;
if (status === 'single') {
limit0 = 47025;
limit15 = 518900;
} else if (status === 'married') {
limit0 = 94050;
limit15 = 583750;
} else { // Head of Household
limit0 = 63000;
limit15 = 551350;
}
// Determine rate based on taxable income
if (income < limit0) {
taxRate = 0.00;
} else if (income niitThreshold) {
// NIIT applies to the lesser of the gain or the amount by which MAGI exceeds threshold
var excessIncome = magi – niitThreshold;
var taxableNiitAmount = Math.min(gain, excessIncome);
niit = taxableNiitAmount * 0.038;
}
var totalTax = taxAmount + niit;
var netProfit = gain – totalTax;
// Update DOM
document.getElementById('displayGain').innerHTML = new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' }).format(gain);
document.getElementById('displayRate').innerHTML = (taxRate * 100).toFixed(1) + "%";
document.getElementById('displayTax').innerHTML = new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' }).format(taxAmount);
document.getElementById('displayNiit').innerHTML = new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' }).format(niit);
document.getElementById('displayNetProfit').innerHTML = new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' }).format(netProfit);
document.getElementById('result').style.display = 'block';
}
Understanding Capital Gains Tax
Capital gains tax is a levy on the profit realized from the sale of a non-inventory asset. The most common capital gains are realized from the sale of stocks, bonds, precious metals, real estate, and property. The tax is calculated on the "gain," which is the difference between the sale price and the original purchase price (cost basis).
Short-Term vs. Long-Term Capital Gains
The duration you hold an asset significantly impacts your tax liability:
Short-Term Capital Gains: Applied to assets held for one year or less. These are taxed as ordinary income, meaning they are subject to your standard federal income tax brackets (ranging from 10% to 37% in 2024).
Long-Term Capital Gains: Applied to assets held for more than one year. These benefit from preferential tax rates, typically 0%, 15%, or 20%, depending on your filing status and taxable income.
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 statutory thresholds:
Single: $200,000
Married Filing Jointly: $250,000
Married Filing Separately: $125,000
This calculator automatically estimates NIIT liability based on the income information provided.
Strategies to Minimize Capital Gains Tax
Investors often use specific strategies to reduce their tax burden. Tax-Loss Harvesting involves selling assets at a loss to offset gains realized elsewhere in your portfolio. Additionally, holding assets for at least a year and a day qualifies you for long-term rates, which can result in significant savings compared to short-term ordinary income rates.
Disclaimer: This calculator provides estimates based on federal tax laws for the 2024 tax year. It does not account for state or local taxes, or specific deductions. Consult a qualified CPA or tax professional for advice specific to your financial situation.