Less than 1 year (Short Term)
More than 1 year (Long Term)
Single
Married Filing Jointly
Head of Household
Used to determine your tax bracket.
Total Capital Gain:$0.00
Estimated Tax Rate:0%
Estimated Tax Owed:$0.00
Net Profit (After Tax):$0.00
function calculateCapitalGains() {
// 1. Retrieve Inputs
var purchase = parseFloat(document.getElementById('purchasePrice').value);
var sale = parseFloat(document.getElementById('salePrice').value);
var duration = document.getElementById('ownershipDuration').value;
var status = document.getElementById('filingStatus').value;
var income = parseFloat(document.getElementById('annualIncome').value);
// 2. Validation
if (isNaN(purchase) || isNaN(sale) || isNaN(income)) {
alert("Please enter valid numbers for Purchase Price, Sale Price, and Annual Income.");
return;
}
// 3. Calculate Raw Gain
var gain = sale – purchase;
// Handle Loss scenario
if (gain <= 0) {
document.getElementById('cgtResultBox').style.display = 'block';
document.getElementById('resGain').innerText = "$" + gain.toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2});
document.getElementById('resRate').innerText = "0%";
document.getElementById('resTax').innerText = "$0.00";
document.getElementById('resNet').innerText = "$" + gain.toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2});
return;
}
var totalTaxableIncome = income + gain;
var estimatedTax = 0;
var appliedRateText = "";
// 4. Tax Logic (Using simplified 2024 brackets)
if (duration === 'short') {
// Short Term = Ordinary Income Tax Rates
// We calculate the tax on the GAIN portion specifically by stacking it on top of income
// Simplified bracket logic for estimation
// Function to calculate tax on a chunk of money based on brackets
var calculateMarginalTax = function(startIncome, amount, filing) {
var tax = 0;
var currentIncome = startIncome;
var amountLeft = amount;
// 2024 Brackets (Simplified for Single/Married)
// Brackets: [Limit, Rate]
var brackets = [];
if (filing === 'single') {
brackets = [
{ limit: 11600, rate: 0.10 },
{ limit: 47150, rate: 0.12 },
{ limit: 100525, rate: 0.22 },
{ limit: 191950, rate: 0.24 },
{ limit: 243725, rate: 0.32 },
{ limit: 609350, rate: 0.35 },
{ limit: Infinity, rate: 0.37 }
];
} else if (filing === 'married') {
brackets = [
{ limit: 23200, rate: 0.10 },
{ limit: 94300, rate: 0.12 },
{ limit: 201050, rate: 0.22 },
{ limit: 383900, rate: 0.24 },
{ limit: 487450, rate: 0.32 },
{ limit: 731200, rate: 0.35 },
{ limit: Infinity, rate: 0.37 }
];
} else { // Head of household (approximate)
brackets = [
{ limit: 16550, rate: 0.10 },
{ limit: 63100, rate: 0.12 },
{ limit: 100500, rate: 0.22 },
{ limit: 191950, rate: 0.24 },
{ limit: 243700, rate: 0.32 },
{ limit: 609350, rate: 0.35 },
{ limit: Infinity, rate: 0.37 }
];
}
var prevLimit = 0;
for (var i = 0; i 0 && amountLeft > 0) {
var taxableAmount = Math.min(spaceInBracket, amountLeft);
tax += taxableAmount * rate;
amountLeft -= taxableAmount;
}
prevLimit = limit;
if (amountLeft <= 0) break;
}
return tax;
};
estimatedTax = calculateMarginalTax(income, gain, status);
var effectiveRate = (estimatedTax / gain) * 100;
appliedRateText = effectiveRate.toFixed(1) + "% (Ordinary Income)";
} else {
// Long Term Capital Gains Rates (0%, 15%, 20%)
// 2024 Thresholds
var rate0 = 0;
var rate15 = 0;
var rate20 = 0;
if (status === 'single') {
rate0 = 47025;
rate15 = 518900;
} else if (status === 'married') {
rate0 = 94050;
rate15 = 583750;
} else { // HOH
rate0 = 63000;
rate15 = 551350;
}
// Logic: The gain stacks ON TOP of ordinary income.
// Check where the income sits relative to CGT brackets
var amountLeft = gain;
var currentTotal = income;
// 0% Bucket
if (currentTotal 0 && currentTotal 0) {
estimatedTax += amountLeft * 0.20;
}
// Net Investment Income Tax (NIIT) – 3.8% if MAGI > Threshold
// Thresholds: Single 200k, Married 250k
var niitThreshold = (status === 'married') ? 250000 : 200000;
var totalAGI = income + gain;
if (totalAGI > niitThreshold) {
var amountSubjectToNiit = Math.min(gain, totalAGI – niitThreshold);
estimatedTax += amountSubjectToNiit * 0.038;
appliedRateText = "LTCG + NIIT";
} else {
appliedRateText = "Long Term Cap Gains";
}
}
// 5. Update Results
var netProfit = gain – estimatedTax;
document.getElementById('cgtResultBox').style.display = 'block';
document.getElementById('resGain').innerText = "$" + gain.toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2});
// If long term, calculate effective percentage for display
if (duration === 'long') {
var finalRate = (estimatedTax / gain) * 100;
document.getElementById('resRate').innerText = finalRate.toFixed(1) + "% (" + appliedRateText + ")";
} else {
document.getElementById('resRate').innerText = appliedRateText;
}
document.getElementById('resTax').innerText = "$" + estimatedTax.toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2});
document.getElementById('resNet').innerText = "$" + netProfit.toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2});
}
Understanding Capital Gains Tax on Your Investments
Calculating your potential tax liability is a crucial step in investment planning. Whether you are selling stocks, real estate, or cryptocurrency, the profit you make—known as a capital gain—is subject to taxation by the IRS. This Capital Gains Tax Calculator helps you estimate how much you will owe and what your net profit will be after taxes.
Short-Term vs. Long-Term Capital Gains
The single most important factor determining your tax rate is the duration for which you held the asset.
Short-Term Capital Gains: If you hold an asset for one year or less before selling, the profit is taxed as ordinary income. This means it is taxed at the same rate as your wages or salary, which can be as high as 37% for high earners.
Long-Term Capital Gains: If you hold an asset for more than one year, you qualify for preferential tax rates. Depending on your taxable income, your rate will be 0%, 15%, or 20%. These rates are significantly lower than standard income tax rates.
2024 Capital Gains Tax Brackets
For the 2024 tax year, the long-term capital gains tax rates are structured as follows (for single filers):
0% Rate: For taxable income up to $47,025.
15% Rate: For taxable income between $47,026 and $518,900.
20% Rate: For taxable income over $518,900.
Note: Married couples filing jointly have higher income thresholds for these brackets.
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. Our calculator automatically estimates this surcharge if your total income exceeds these thresholds.
Strategies to Reduce Your Tax Liability
There are several ways to legally minimize the amount of capital gains tax you owe:
Hold for over a year: Whenever possible, hold assets for at least a year and a day to qualify for the lower long-term rates.
Tax-Loss Harvesting: You can offset your capital gains by selling underperforming assets at a loss. These losses can cancel out your gains, reducing your overall taxable income.
Utilize Tax-Advantaged Accounts: Investments held in 401(k)s or IRAs grow tax-deferred or tax-free, meaning you don't pay capital gains tax on trades made within the account.