Estimate your federal and state tax liability on investment sales.
$
$
More than 1 year (Long-term)
1 year or less (Short-term)
$
Includes salary, wages, etc.
Single
Married Filing Jointly
Head of Household
Calculation Results
$0.00
0%
$0.00
$0.00
$0.00
$0.00
$0.00
Understanding Capital Gains Tax
Capital gains tax is a levy assessed on the positive difference between the sale price of the asset and its original purchase price. Whether you are selling stocks, real estate, or a business, understanding how this tax is calculated is crucial for financial planning. This calculator helps you estimate your potential tax liability based on the 2024 tax brackets.
Short-Term vs. Long-Term Capital Gains
The duration you hold an asset significantly impacts 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 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.
2024 Long-Term Capital Gains Tax Brackets
For the 2024 tax year, the long-term capital gains tax rates are determined by your taxable income thresholds:
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)
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:
$200,000 for Single or Head of Household filers
$250,000 for Married Filing Jointly
This surtax is applied to the lesser of your net investment income or the amount by which your MAGI exceeds the threshold.
How to Calculate Your Capital Gain
The basic formula for calculating capital gains is:
Capital Gain = Selling Price – (Purchase Price + Transaction Costs)
If the result is positive, it is a capital gain. If negative, it is a capital loss, which can potentially be used to offset other gains or up to $3,000 of ordinary income per year.
Strategies to Minimize Capital Gains Tax
There are several strategies investors use to reduce their tax burden:
Hold for over a year: Waiting at least one year and one day before selling moves your gain from short-term to long-term rates, potentially saving up to 20% in taxes.
Tax-Loss Harvesting: Selling underperforming assets at a loss can offset gains realized from other assets.
Utilize Tax-Advantaged Accounts: Trading within a 401(k) or IRA defers taxes until withdrawal (or eliminates them in the case of a Roth IRA).
Wait for Low-Income Years: If you expect your income to drop (e.g., retirement), selling then might qualify you for the 0% capital gains rate.
function calculateCapitalGains() {
// 1. Get Inputs
var buyPrice = parseFloat(document.getElementById('buyPrice').value);
var sellPrice = parseFloat(document.getElementById('sellPrice').value);
var annualIncome = parseFloat(document.getElementById('annualIncome').value);
var stateRate = parseFloat(document.getElementById('stateRate').value);
var filingStatus = document.getElementById('filingStatus').value;
var duration = document.getElementById('duration').value;
// Validation
if (isNaN(buyPrice) || isNaN(sellPrice) || isNaN(annualIncome)) {
alert("Please enter valid numbers for prices and income.");
return;
}
if (isNaN(stateRate)) {
stateRate = 0;
}
// 2. Calculate Gross Gain
var gain = sellPrice – buyPrice;
// If loss, taxes are 0 (simplified logic)
if (gain 609350) marginalRate = 0.37;
else if (annualIncome > 243725) marginalRate = 0.35;
else if (annualIncome > 191950) marginalRate = 0.32;
else if (annualIncome > 100525) marginalRate = 0.24;
else if (annualIncome > 47150) marginalRate = 0.22;
else if (annualIncome > 11600) marginalRate = 0.12;
else marginalRate = 0.10;
} else if (filingStatus === 'married') {
if (annualIncome > 731200) marginalRate = 0.37;
else if (annualIncome > 487450) marginalRate = 0.35;
else if (annualIncome > 383900) marginalRate = 0.32;
else if (annualIncome > 201050) marginalRate = 0.24;
else if (annualIncome > 94300) marginalRate = 0.22;
else if (annualIncome > 23200) marginalRate = 0.12;
else marginalRate = 0.10;
} else { // Head of household
if (annualIncome > 609350) marginalRate = 0.37;
else if (annualIncome > 243700) marginalRate = 0.35;
else if (annualIncome > 191950) marginalRate = 0.32;
else if (annualIncome > 100500) marginalRate = 0.24;
else if (annualIncome > 63100) marginalRate = 0.22;
else if (annualIncome > 16550) marginalRate = 0.12;
else marginalRate = 0.10;
}
federalTax = gain * marginalRate;
appliedRateText = (marginalRate * 100).toFixed(0) + "% (Ordinary Income)";
} else {
// Long Term: 0%, 15%, 20%
// 2024 Thresholds
var rate0Limit, rate15Limit;
if (filingStatus === 'single') {
rate0Limit = 47025;
rate15Limit = 518900;
} else if (filingStatus === 'married') {
rate0Limit = 94050;
rate15Limit = 583750;
} else { // head
rate0Limit = 63000;
rate15Limit = 551350;
}
// Determine rate based on Total Income (Income + Gain is usually how it's stacked,
// but standard simple calculators use taxable income to determine the bracket).
// Logic: The rate is determined by where the income falls.
var longTermRate = 0;
if (annualIncome > rate15Limit) {
longTermRate = 0.20;
} else if (annualIncome > rate0Limit) {
longTermRate = 0.15;
} else {
longTermRate = 0.00;
}
federalTax = gain * longTermRate;
appliedRateText = (longTermRate * 100).toFixed(0) + "% (Long Term)";
}
// 4. Calculate NIIT (Net Investment Income Tax)
// 3.8% if MAGI > Threshold (200k Single, 250k Married)
var niitThreshold = (filingStatus === 'married') ? 250000 : 200000;
var niitTax = 0;
// Total MAGI approx = Annual Income + Gain
var totalMAGI = annualIncome + gain;
if (totalMAGI > niitThreshold) {
// NIIT applies to the lesser of the Gain OR the amount over threshold
var amountOverThreshold = totalMAGI – niitThreshold;
var taxableNIITBase = Math.min(gain, amountOverThreshold);
niitTax = taxableNIITBase * 0.038;
}
// 5. Calculate State Tax
var stateTaxAmount = gain * (stateRate / 100);
// 6. Totals
var totalTax = federalTax + niitTax + stateTaxAmount;
var netProfit = gain – totalTax;
// 7. Update UI
document.getElementById('resultSection').style.display = 'block';
document.getElementById('displayTotalGain').innerText = formatMoney(gain);
document.getElementById('displayBracket').innerText = appliedRateText;
document.getElementById('displayFedTax').innerText = formatMoney(federalTax);
document.getElementById('displayNiit').innerText = formatMoney(niitTax);
document.getElementById('displayStateTax').innerText = formatMoney(stateTaxAmount);
document.getElementById('displayTotalTax').innerText = formatMoney(totalTax);
document.getElementById('displayNetProfit').innerText = formatMoney(netProfit);
}
function formatMoney(amount) {
return '$' + amount.toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2});
}