Estimate your federal capital gains taxes based on your annual income, filing status, and asset holding period.
Less than 1 year (Short-Term)
More than 1 year (Long-Term)
Assets held > 1 year benefit from lower tax rates.
Single
Married Filing Jointly
Head of Household
Your taxable income from wages, etc.
Calculation Results
Total Capital Gain:$0.00
Tax Type Applied:Long Term
Federal Tax Rate:0%
Federal Tax Amount:$0.00
Net Investment Income Tax (NIIT):$0.00
State Tax Amount (Est.):$0.00
Total Estimated Tax:$0.00
Net Profit After Tax:$0.00
Understanding Capital Gains Tax
When you sell an asset (like stocks, bonds, or real estate) for more than you paid for it, the profit is known as a capital gain. The Internal Revenue Service (IRS) taxes these gains differently depending on how long you held the asset before selling.
Short-Term vs. Long-Term Capital Gains
The holding period determines your tax rate:
Short-Term Capital Gains: 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%).
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.
2024 Long-Term Capital Gains Tax Brackets
The following table outlines the income thresholds for long-term capital gains tax rates for the 2024 tax year:
Tax Rate
Single
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
Net Investment Income Tax (NIIT)
In addition to standard capital gains tax, high-income earners may be subject to an additional 3.8% Net Investment Income Tax (NIIT). This applies if your Modified Adjusted Gross Income (MAGI) exceeds the following thresholds:
Single: $200,000
Married Filing Jointly: $250,000
Married Filing Separately: $125,000
The calculator above automatically estimates this surcharge if your total income (Salary + Capital Gain) exceeds these limits.
How to Lower Your Capital Gains Tax
Hold for over a year: Waiting until you qualify for long-term status is the most effective way to reduce your rate significantly.
Tax-Loss Harvesting: You can offset capital gains by selling other investments that have lost value. Losses can offset gains dollar-for-dollar.
Invest in Tax-Advantaged Accounts: Trading within a 401(k) or IRA does not trigger immediate capital gains taxes.
Utilize the Primary Residence Exclusion: If you are selling your main home, you may exclude up to $250,000 (single) or $500,000 (married) of gain from taxes, provided you meet the ownership and use tests.
function calculateCapitalGains() {
// 1. Get Inputs
var purchasePrice = parseFloat(document.getElementById('purchasePrice').value);
var salePrice = parseFloat(document.getElementById('salePrice').value);
var holdingPeriod = document.getElementById('holdingPeriod').value;
var filingStatus = document.getElementById('filingStatus').value;
var annualIncome = parseFloat(document.getElementById('annualIncome').value);
var stateRate = parseFloat(document.getElementById('stateRate').value);
// Validation
if (isNaN(purchasePrice) || isNaN(salePrice) || isNaN(annualIncome)) {
alert("Please enter valid numbers for prices and income.");
return;
}
if (isNaN(stateRate)) {
stateRate = 0;
}
// 2. Basic Math
var capitalGain = salePrice – purchasePrice;
var totalIncome = annualIncome + capitalGain; // Simplified MAGI calculation
var federalTax = 0;
var niit = 0;
var rateApplied = "0%";
// Show results container
document.getElementById('resultsArea').style.display = 'block';
if (capitalGain niitThreshold) {
// NIIT applies to the lesser of: Net Investment Income (Capital Gain here) OR Excess over threshold
var excessIncome = totalIncome – niitThreshold;
var amountSubjectToNiit = Math.min(capitalGain, excessIncome);
niit = amountSubjectToNiit * 0.038;
}
// — Federal Tax Calculation —
if (holdingPeriod === 'short') {
// SHORT TERM: Taxed as Ordinary Income
// Simplified logic: We assume the capital gain sits on "top" of annual income.
// We need 2024 brackets.
var brackets;
if (filingStatus === 'married') {
brackets = [
{ cap: 23200, rate: 0.10 },
{ cap: 94300, rate: 0.12 },
{ cap: 201050, rate: 0.22 },
{ cap: 383900, rate: 0.24 },
{ cap: 487450, rate: 0.32 },
{ cap: 731200, rate: 0.35 },
{ cap: Infinity, rate: 0.37 }
];
} else if (filingStatus === 'head') {
brackets = [
{ cap: 16550, rate: 0.10 },
{ cap: 63100, rate: 0.12 },
{ cap: 100500, rate: 0.22 },
{ cap: 191950, rate: 0.24 },
{ cap: 243700, rate: 0.32 },
{ cap: 609350, rate: 0.35 },
{ cap: Infinity, rate: 0.37 }
];
} else { // Single
brackets = [
{ cap: 11600, rate: 0.10 },
{ cap: 47150, rate: 0.12 },
{ cap: 100525, rate: 0.22 },
{ cap: 191950, rate: 0.24 },
{ cap: 243725, rate: 0.32 },
{ cap: 609350, rate: 0.35 },
{ cap: Infinity, rate: 0.37 }
];
}
federalTax = calculateProgressiveTax(annualIncome, capitalGain, brackets);
rateApplied = "Ordinary Income Rates";
} else {
// LONG TERM: 0%, 15%, 20%
// Brackets apply to Taxable Income.
// We calculate tax on income without gain (likely 0 for CG logic specifically, but here we stack)
// Actually, for CG tax, we check where the income+gain falls in the specific CG brackets.
// 2024 Long Term Brackets
var ltBrackets;
if (filingStatus === 'married') {
ltBrackets = [
{ cap: 94050, rate: 0 },
{ cap: 583750, rate: 0.15 },
{ cap: Infinity, rate: 0.20 }
];
} else if (filingStatus === 'head') {
ltBrackets = [
{ cap: 63000, rate: 0 },
{ cap: 551350, rate: 0.15 },
{ cap: Infinity, rate: 0.20 }
];
} else { // Single
ltBrackets = [
{ cap: 47025, rate: 0 },
{ cap: 518900, rate: 0.15 },
{ cap: Infinity, rate: 0.20 }
];
}
// The capital gain is stacked ON TOP of ordinary income.
// Logic:
// 1. Calculate how much room is left in 0% bucket using annualIncome.
// 2. Fill 0% bucket.
// 3. Fill 15% bucket.
// 4. Remainder in 20% bucket.
var remainingGain = capitalGain;
var currentIncomeLevel = annualIncome;
// 0% Bucket
var limit0 = ltBrackets[0].cap;
if (currentIncomeLevel 0) {
var limit15 = ltBrackets[1].cap;
if (currentIncomeLevel 0) {
federalTax += remainingGain * 0.20;
}
// Calculate effective rate for display
var effRate = (federalTax / capitalGain) * 100;
rateApplied = effRate.toFixed(1) + "% (Effective)";
}
// — State Tax Calculation —
var stateTax = capitalGain * (stateRate / 100);
// — Totals —
var totalTax = federalTax + niit + stateTax;
var netProfit = capitalGain – totalTax;
// 4. Update DOM
document.getElementById('displayTotalGain').innerHTML = formatMoney(capitalGain);
document.getElementById('displayTaxType').innerHTML = (holdingPeriod === 'short') ? "Short Term (Ordinary Income)" : "Long Term";
document.getElementById('displayFedRate').innerHTML = rateApplied;
document.getElementById('displayFedTax').innerHTML = formatMoney(federalTax);
document.getElementById('displayNiit').innerHTML = formatMoney(niit);
document.getElementById('displayStateTax').innerHTML = formatMoney(stateTax);
document.getElementById('displayTotalTax').innerHTML = formatMoney(totalTax);
document.getElementById('displayNetProfit').innerHTML = formatMoney(netProfit);
}
// Helper to calculate progressive tax for Short Term
function calculateProgressiveTax(baseIncome, gainAmount, brackets) {
var tax = 0;
var start = baseIncome;
var end = baseIncome + gainAmount;
// We only care about the tax generated by the chunk between start and end
// Simplest way: Calculate Total Tax on (Income+Gain) minus Total Tax on (Income)
var taxOnTotal = getTaxFromBrackets(end, brackets);
var taxOnBase = getTaxFromBrackets(start, brackets);
return taxOnTotal – taxOnBase;
}
function getTaxFromBrackets(income, brackets) {
var totalTax = 0;
var previousCap = 0;
for (var i = 0; i previousCap) {
var taxableInBracket = Math.min(income, cap) – previousCap;
totalTax += taxableInBracket * rate;
previousCap = cap;
} else {
break;
}
}
return totalTax;
}
function formatMoney(num) {
return '$' + num.toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,');
}