Calculate your estimated federal and state taxes on investment profits.
Excluding this capital gain
Single
Married Filing Jointly
Head of Household
Short Term (Less than 1 year)
Long Term (More than 1 year)
Total Capital Gain:$0.00
Federal Tax Rate Applied:0%
Est. Federal Tax:$0.00
Net Investment Income Tax (NIIT):$0.00
Est. State Tax:$0.00
Total Estimated Tax:$0.00
Net Profit After Tax:$0.00
function formatCurrency(num) {
return new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD' }).format(num);
}
function calculateCapitalGains() {
// 1. Get Inputs
var buyPrice = parseFloat(document.getElementById('cgt_buy_price').value);
var sellPrice = parseFloat(document.getElementById('cgt_sell_price').value);
var income = parseFloat(document.getElementById('cgt_income').value);
var stateRate = parseFloat(document.getElementById('cgt_state_rate').value) || 0;
var status = document.getElementById('cgt_status').value;
var duration = document.getElementById('cgt_duration').value;
// 2. Validation
if (isNaN(buyPrice) || isNaN(sellPrice) || isNaN(income)) {
alert("Please enter valid numbers for prices and income.");
return;
}
// 3. Calculate Gain
var totalGain = sellPrice – buyPrice;
var taxableGain = totalGain > 0 ? totalGain : 0;
// 4. Calculate Federal Tax
var fedTaxAmount = 0;
var fedRateLabel = "0%";
// Federal Brackets 2024 (Approximate)
// Long Term Brackets
var lt_0_limit = (status === 'married') ? 94050 : (status === 'head') ? 63000 : 47025;
var lt_15_limit = (status === 'married') ? 583750 : (status === 'head') ? 551350 : 518900;
// Short Term (Ordinary Income) Estimator (Simplified Marginal Rates)
function getMarginalRate(inc, stat) {
// Very simplified progressive estimation for the widget purpose
// Single Filers roughly
if (stat === 'married') inc = inc / 2; // Normalize married to single width roughly for estimation
if (inc < 11600) return 0.10;
if (inc < 47150) return 0.12;
if (inc < 100525) return 0.22;
if (inc < 191950) return 0.24;
if (inc < 243725) return 0.32;
if (inc lt_0_limit, amount is 0.
// Wait, logic correction:
var remainingGain = taxableGain;
// Check headroom in 0% bracket
var roomIn0 = Math.max(0, lt_0_limit – incomeStart);
var tax0 = Math.min(remainingGain, roomIn0);
remainingGain -= tax0;
// Check headroom in 15% bracket
var roomIn15 = Math.max(0, lt_15_limit – Math.max(incomeStart, lt_0_limit));
var tax15 = Math.min(remainingGain, roomIn15);
remainingGain -= tax15;
// Remaining is 20%
var tax20 = remainingGain;
fedTaxAmount = (tax15 * 0.15) + (tax20 * 0.20);
// Determine effective rate for label
if (taxableGain > 0) {
var effectiveRate = (fedTaxAmount / taxableGain) * 100;
fedRateLabel = effectiveRate.toFixed(1) + "% (Effective)";
} else {
fedRateLabel = "0%";
}
}
// 5. NIIT Calculation (Net Investment Income Tax)
// 3.8% if MAGI > Threshold (Single 200k, Married 250k)
var niitThreshold = (status === 'married') ? 250000 : 200000;
var niitTax = 0;
var magi = income + taxableGain;
if (magi > niitThreshold && taxableGain > 0) {
// Tax applies to the lesser of: Net Investment Income OR Excess MAGI over threshold
var excessIncome = magi – niitThreshold;
var taxableNiitAmount = Math.min(taxableGain, excessIncome);
niitTax = taxableNiitAmount * 0.038;
}
// 6. State Tax
var stateTaxAmount = taxableGain * (stateRate / 100);
// 7. Totals
var totalTax = fedTaxAmount + stateTaxAmount + niitTax;
var netProfit = totalGain – totalTax;
// 8. Update DOM
document.getElementById('res_total_gain').innerHTML = formatCurrency(totalGain);
// Handle Loss
if (totalGain < 0) {
document.getElementById('res_total_gain').classList.add('cgt-highlight-loss');
document.getElementById('res_fed_rate').innerText = "N/A";
document.getElementById('res_fed_tax').innerText = "$0.00";
document.getElementById('res_niit_tax').innerText = "$0.00";
document.getElementById('res_state_tax').innerText = "$0.00";
document.getElementById('res_total_tax').innerText = "$0.00";
document.getElementById('res_net_profit').innerHTML = formatCurrency(totalGain);
document.getElementById('res_net_profit').style.color = "#c0392b";
} else {
document.getElementById('res_total_gain').classList.remove('cgt-highlight-loss');
document.getElementById('res_fed_rate').innerText = fedRateLabel;
document.getElementById('res_fed_tax').innerText = formatCurrency(fedTaxAmount);
document.getElementById('res_niit_tax').innerText = formatCurrency(niitTax);
document.getElementById('res_state_tax').innerText = formatCurrency(stateTaxAmount);
document.getElementById('res_total_tax').innerText = formatCurrency(totalTax);
document.getElementById('res_net_profit').innerText = formatCurrency(netProfit);
document.getElementById('res_net_profit').style.color = "#27ae60";
}
document.getElementById('cgt_results').style.display = 'block';
}
Understanding Capital Gains Tax
When you sell an asset—such as stocks, real estate, or a business—for more than you paid for it, the profit is referred to as a "capital gain." The IRS taxes these profits differently depending on how long you held the asset before selling it. This Capital Gains Tax Calculator helps investors estimate their potential tax liability to better plan their financial exits.
Long-Term vs. Short-Term Capital Gains
The duration of your ownership is the primary factor determining your tax rate:
Short-Term Capital Gains: Assets held for one year or less. These gains are taxed as ordinary income, meaning they are added to your salary and other earnings and taxed at your marginal tax bracket (ranging from 10% to 37%).
Long-Term Capital Gains: Assets held for more than one year. These qualify for preferential tax rates, typically 0%, 15%, or 20%, depending on your taxable income and filing status. This lower rate is designed to encourage long-term investment.
2024 Long-Term Capital Gains Tax Brackets
For the 2024 tax year, the federal rates for long-term gains are structured as follows:
0% Rate: Applies if your taxable income is below $47,025 (Single) or $94,050 (Married Filing Jointly).
15% Rate: Applies if your income is between $47,025 and $518,900 (Single) or between $94,050 and $583,750 (Married).
20% Rate: Applies if your income exceeds the thresholds above.
Net Investment Income Tax (NIIT)
High-income earners may face an additional 3.8% surtax known as the Net Investment Income Tax (NIIT). This applies if your Modified Adjusted Gross Income (MAGI) exceeds $200,000 for single filers or $250,000 for married couples filing jointly. This calculator automatically checks if your combined income and gains trigger this surcharge.
State Capital Gains Taxes
Don't forget that most states also tax capital gains. While the federal government offers lower rates for long-term holdings, many states treat all capital gains as ordinary income. States like California impose high taxes on gains, whereas states like Florida or Texas have no state income tax. Enter your specific state tax rate in the calculator above for the most accurate "Net Profit" estimation.
Strategies to Minimize Liability
Investors often use strategies such as Tax-Loss Harvesting (selling losing assets to offset gains) or holding assets for at least one year and one day to qualify for the lower long-term rates. Always consult with a CPA or tax professional before making significant financial moves.