Estimate your federal tax liability on investment sales.
Single
Married Filing Jointly
Head of Household
Less than 1 year (Short-Term)
More than 1 year (Long-Term)
Total Capital Gain:–
Tax Rate Category:–
Estimated Federal Tax Rate:–
Net Investment Income Tax (NIIT):–
Total Estimated Tax:–
Net Profit After Tax:–
function calculateCapitalGains() {
// 1. Get Input Values
var purchasePrice = parseFloat(document.getElementById("purchasePrice").value);
var salePrice = parseFloat(document.getElementById("salePrice").value);
var annualIncome = parseFloat(document.getElementById("annualIncome").value);
var status = document.getElementById("filingStatus").value;
var duration = document.getElementById("ownershipDuration").value;
// 2. Validation
if (isNaN(purchasePrice) || isNaN(salePrice) || isNaN(annualIncome)) {
alert("Please enter valid numbers for all financial fields.");
return;
}
// 3. Calculate Base Gain
var gain = salePrice – purchasePrice;
// Handle Loss
if (gain 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 (status === "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 {
categoryText = "Long-Term Capital Gains";
// 2024 Long Term Capital Gains Brackets
if (status === "single") {
if (annualIncome > 518900) taxRate = 0.20;
else if (annualIncome > 47025) taxRate = 0.15;
else taxRate = 0.0;
} else if (status === "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;
}
}
// 5. Calculate NIIT (Net Investment Income Tax) – 3.8% surcharge
// Thresholds: Single $200k, Married $250k, Head $200k
var niitThreshold = (status === "married") ? 250000 : 200000;
// NIIT applies to the lesser of the Net Investment Income (the gain)
// OR the amount by which MAGI exceeds the threshold.
// Simplified Logic: If Total Income (Income input assumed to include gain for simplicity, or add it)
// We will assume 'annualIncome' is income BEFORE the gain, so we add them.
var totalMAGI = annualIncome + gain;
if (totalMAGI > niitThreshold) {
var amountOverThreshold = totalMAGI – niitThreshold;
// Taxable for NIIT is lesser of Gain OR Amount Over Threshold
var niitTaxable = Math.min(gain, amountOverThreshold);
niitAmount = niitTaxable * 0.038;
}
// 6. Final Computations
taxAmount = (gain * taxRate) + niitAmount;
var totalTaxRateDisplay = (taxRate * 100).toFixed(1) + "%";
var netProfit = gain – taxAmount;
// 7. Update UI
document.getElementById("resultBox").style.display = "block";
document.getElementById("displayGain").innerText = "$" + gain.toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2});
document.getElementById("displayCategory").innerText = categoryText;
document.getElementById("displayRate").innerText = totalTaxRateDisplay + " (Base)";
document.getElementById("displayNiit").innerText = "$" + niitAmount.toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2});
document.getElementById("displayTax").innerText = "$" + taxAmount.toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2});
document.getElementById("displayProfit").innerText = "$" + netProfit.toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2});
}
Understanding Capital Gains Tax
Capital gains tax is a levy on the profit realized from the sale of a non-inventory asset that was purchased at a cost amount that was lower than the amount realized on the sale. The most common capital gains are realized from the sale of stocks, bonds, precious metals, and property.
Short-Term vs. Long-Term
The duration you hold an asset significantly impacts your tax bill:
Short-Term Capital Gains: Assets held for one year or less. These are taxed as ordinary income, meaning they are subject to your standard income tax bracket (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 taxable income and filing status.
Net Investment Income Tax (NIIT)
High-income earners may be subject to an additional 3.8% Net Investment Income Tax. This calculator automatically estimates NIIT if your total modified adjusted gross income (including the gain) exceeds $200,000 for single filers or $250,000 for married couples filing jointly.
How to Use This Calculator
Enter your Original Purchase Price (Cost Basis).
Enter the final Sale Price.
Input your total Annual Taxable Income (excluding this sale). This determines your tax bracket.
Select your Filing Status and Ownership Duration.
Click "Calculate Tax" to see your estimated liability and net profit.