Estimate your federal and state tax liability on investment sales.
Original cost plus buying fees.
Final selling price minus selling fees.
Less than 1 Year (Short-term)
More than 1 Year (Long-term)
Your regular income excluding this gain.
Single
Married Filing Jointly
Head of Household
Enter 0 if you live in a no-tax state.
Total Capital Gain:$0.00
Estimated Federal Tax:$0.00
Net Investment Income Tax (NIIT):$0.00
Estimated State Tax:$0.00
Total Tax Liability:$0.00
Net Profit:$0.00
function calculateCapitalGains() {
// 1. Get Inputs
var purchasePrice = parseFloat(document.getElementById('purchasePrice').value);
var salePrice = parseFloat(document.getElementById('salePrice').value);
var annualIncome = parseFloat(document.getElementById('annualIncome').value);
var filingStatus = document.getElementById('filingStatus').value;
var duration = document.getElementById('ownershipDuration').value;
var stateTaxRate = parseFloat(document.getElementById('stateTaxRate').value);
// Validation and Defaulting
if (isNaN(purchasePrice)) purchasePrice = 0;
if (isNaN(salePrice)) salePrice = 0;
if (isNaN(annualIncome)) annualIncome = 0;
if (isNaN(stateTaxRate)) stateTaxRate = 0;
// 2. Base Calculation
var capitalGain = salePrice – purchasePrice;
var fedTax = 0;
var niitTax = 0;
var stateTax = 0;
// If there is a loss or no gain, taxes are 0 (simplified loss carryover logic not included)
if (capitalGain > 0) {
// — Federal Tax Logic —
if (duration === 'short') {
// Short Term: Taxed as Ordinary Income
// Simplified estimate: Use marginal bracket based on Income + Gain
var totalIncome = annualIncome + capitalGain;
var marginalRate = 0.10; // default lowest
// 2024 Simplified Tax Brackets (Standard Deduction not applied for simplicity of marginal estimation)
if (filingStatus === 'single') {
if (totalIncome > 609350) marginalRate = 0.37;
else if (totalIncome > 243725) marginalRate = 0.35;
else if (totalIncome > 191950) marginalRate = 0.32;
else if (totalIncome > 100525) marginalRate = 0.24;
else if (totalIncome > 47150) marginalRate = 0.22;
else if (totalIncome > 11600) marginalRate = 0.12;
} else if (filingStatus === 'married') {
if (totalIncome > 731200) marginalRate = 0.37;
else if (totalIncome > 487450) marginalRate = 0.35;
else if (totalIncome > 383900) marginalRate = 0.32;
else if (totalIncome > 201050) marginalRate = 0.24;
else if (totalIncome > 94300) marginalRate = 0.22;
else if (totalIncome > 23200) marginalRate = 0.12;
} else { // Head of Household
if (totalIncome > 609350) marginalRate = 0.37;
else if (totalIncome > 243700) marginalRate = 0.35;
else if (totalIncome > 191950) marginalRate = 0.32;
else if (totalIncome > 100500) marginalRate = 0.24;
else if (totalIncome > 63100) marginalRate = 0.22;
else if (totalIncome > 16550) marginalRate = 0.12;
}
// Estimate tax specifically on the gain portion
fedTax = capitalGain * marginalRate;
} else {
// Long Term: 0%, 15%, 20% Brackets
// 2024 Long Term Capital Gains Brackets
var limit0 = 0;
var limit15 = 0;
if (filingStatus === 'single') {
limit0 = 47025;
limit15 = 518900;
} else if (filingStatus === 'married') {
limit0 = 94050;
limit15 = 583750;
} else { // Head of household
limit0 = 63000;
limit15 = 551350;
}
// Calculation logic: Stack income first, then gain sits on top
var amountIn0 = Math.max(0, Math.min(annualIncome + capitalGain, limit0) – annualIncome);
var amountIn15 = Math.max(0, Math.min(annualIncome + capitalGain, limit15) – Math.max(annualIncome, limit0));
var amountIn20 = Math.max(0, (annualIncome + capitalGain) – Math.max(annualIncome, limit15));
fedTax = (amountIn15 * 0.15) + (amountIn20 * 0.20);
}
// — NIIT Logic (3.8% Net Investment Income Tax) —
// Thresholds: $200k (Single/Head), $250k (Married)
var niitThreshold = (filingStatus === 'married') ? 250000 : 200000;
var magi = annualIncome + capitalGain;
if (magi > niitThreshold) {
var amountSubjectToNiit = Math.min(capitalGain, magi – niitThreshold);
niitTax = amountSubjectToNiit * 0.038;
}
// — State Tax Logic —
stateTax = capitalGain * (stateTaxRate / 100);
}
var totalTax = fedTax + niitTax + stateTax;
var netProfit = capitalGain – totalTax;
// 3. Display Results
var currencyFormatter = new Intl.NumberFormat('en-US', {
style: 'currency',
currency: 'USD',
minimumFractionDigits: 2
});
document.getElementById('displayTotalGain').innerText = currencyFormatter.format(capitalGain);
document.getElementById('displayFedTax').innerText = currencyFormatter.format(fedTax);
document.getElementById('displayNiitTax').innerText = currencyFormatter.format(niitTax);
document.getElementById('displayStateTax').innerText = currencyFormatter.format(stateTax);
document.getElementById('displayTotalTax').innerText = currencyFormatter.format(totalTax);
document.getElementById('displayNetProfit').innerText = currencyFormatter.format(netProfit);
document.getElementById('cgt-result').style.display = 'block';
}
How Capital Gains Tax Works
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.
Short-term vs. Long-term Holdings
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 added to your salary and taxed at your regular marginal tax rate (up to 37% in 2024).
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.
2024 Long-Term Capital Gains Tax Brackets
For the 2024 tax year, the long-term rates are applied based on your taxable income:
0% Rate: Single filers earning up to $47,025 (Married up to $94,050).
15% Rate: Single filers earning up to $518,900 (Married up to $583,750).
20% Rate: Income above the 15% threshold.
Net Investment Income Tax (NIIT)
High-income earners may also 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 filers or $250,000 for married couples filing jointly.
Strategies to Reduce Liability
Investors often use strategies like Tax-Loss Harvesting (selling losing investments to offset gains) or holding assets for over a year to qualify for long-term rates to minimize their tax burden.
Disclaimer: This calculator provides estimates based on 2024 tax tables. Tax laws are complex and subject to change. Always consult a certified tax professional (CPA) for advice specific to your financial situation.