Short Term (Less than 1 year)
Long Term (More than 1 year)
Total Capital Gain:$0.00
Estimated Federal Tax:$0.00
Net Profit (After Tax):$0.00
Effective Tax Rate:0%
How Capital Gains Tax Works
Understanding capital gains tax is crucial for investors looking to maximize their net returns. When you sell an asset—whether it's stocks, cryptocurrency, real estate, or a business—for more than you paid for it, the profit is considered a "capital gain." The IRS taxes this profit differently depending on how long you held the asset.
Short-Term vs. Long-Term Capital Gains
The duration of ownership is the primary factor determining your tax rate:
Short-Term Capital Gains: Assets held for one year or less. These are taxed as ordinary income, meaning they are added to your wages and salary and taxed at your regular marginal tax bracket (ranging from 10% to 37% in 2024).
Long-Term Capital Gains: Assets held for more than one year. These benefit from preferential tax rates (0%, 15%, or 20%), which are generally lower than standard income tax rates.
2024 Long-Term Capital Gains Tax Brackets
For the 2024 tax year, long-term capital gains rates are applied based on your total taxable income and filing status. The calculator above uses the following thresholds:
Single Filers:
0% Rate: Income up to $47,025
15% Rate: Income between $47,026 and $518,900
20% Rate: Income over $518,900
Married Filing Jointly:
0% Rate: Income up to $94,050
15% Rate: Income between $94,051 and $583,750
20% Rate: Income over $583,750
How to Lower Your Capital Gains Tax
Investors often use strategies such as Tax-Loss Harvesting (selling losing investments to offset gains) or holding assets for at least a year and a day to qualify for long-term rates. Additionally, utilizing tax-advantaged accounts like 401(k)s or IRAs can defer or eliminate these taxes entirely depending on the account type.
Disclaimer: This calculator provides an estimate based on 2024 federal tax brackets. It does not account for state or local taxes, Net Investment Income Tax (NIIT), or specific deductions. Tax laws are complex and subject to change. Please consult a certified tax professional or CPA for advice specific to your financial situation.
function calculateTax() {
// 1. Get input values
var buyPrice = parseFloat(document.getElementById("buyPrice").value);
var sellPrice = parseFloat(document.getElementById("sellPrice").value);
var income = parseFloat(document.getElementById("annualIncome").value);
var status = document.getElementById("filingStatus").value;
var duration = document.getElementById("assetDuration").value;
// 2. Validate inputs
if (isNaN(buyPrice) || isNaN(sellPrice) || isNaN(income)) {
alert("Please enter valid numbers for prices and income.");
return;
}
// 3. Calculate Gain
var gain = sellPrice – buyPrice;
// If loss or break-even
if (gain <= 0) {
document.getElementById("displayGain").innerText = "$" + gain.toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2});
document.getElementById("displayTax").innerText = "$0.00";
document.getElementById("displayNet").innerText = "$" + gain.toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2});
document.getElementById("displayRate").innerText = "0%";
document.getElementById("cgt-results").style.display = "block";
return;
}
var estimatedTax = 0;
// 4. Logic for Short-Term (Ordinary Income Rates 2024 Simplified)
// Note: Short-term gains stack on top of annual income.
// We calculate tax on (income + gain) minus tax on (income).
if (duration === "short") {
estimatedTax = calculateOrdinaryTax(income + gain, status) – calculateOrdinaryTax(income, status);
}
// 5. Logic for Long-Term (Preferential Rates 0%, 15%, 20%)
// Note: Long-term gains also stack on top of ordinary income for bracket determination.
else {
estimatedTax = calculateLongTermTax(income, gain, status);
}
// 6. Calculate Results
var netProfit = gain – estimatedTax;
var effectiveRate = (estimatedTax / gain) * 100;
// 7. Update DOM
document.getElementById("displayGain").innerText = "$" + gain.toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2});
document.getElementById("displayTax").innerText = "$" + estimatedTax.toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2});
document.getElementById("displayNet").innerText = "$" + netProfit.toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2});
document.getElementById("displayRate").innerText = effectiveRate.toFixed(1) + "%";
document.getElementById("cgt-results").style.display = "block";
}
// Helper: Calculate Ordinary Income Tax (2024 Brackets)
function calculateOrdinaryTax(taxableIncome, status) {
var tax = 0;
var brackets = [];
// 2024 Ordinary Income Brackets
if (status === "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 (status === "married_joint") {
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
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 previousLimit = 0;
for (var i = 0; i currentLimit) {
tax += (currentLimit – previousLimit) * rate;
previousLimit = currentLimit;
} else {
tax += (taxableIncome – previousLimit) * rate;
break;
}
}
return tax;
}
// Helper: Calculate Long Term Capital Gains Tax (2024 Brackets)
function calculateLongTermTax(baseIncome, gainAmount, status) {
// Thresholds for 0%, 15%, 20%
var limit0 = 0;
var limit15 = 0;
if (status === "single") {
limit0 = 47025;
limit15 = 518900;
} else if (status === "married_joint") {
limit0 = 94050;
limit15 = 583750;
} else { // Head of Household
limit0 = 63000;
limit15 = 551350;
}
// We fill buckets starting from baseIncome
var tax = 0;
var incomeRemaining = gainAmount;
var currentStack = baseIncome;
// Bucket 1: 0% Tax
if (currentStack < limit0) {
var room = limit0 – currentStack;
var fill = Math.min(room, incomeRemaining);
// Tax is 0 for this portion
incomeRemaining -= fill;
currentStack += fill;
}
if (incomeRemaining <= 0) return tax;
// Bucket 2: 15% Tax
if (currentStack < limit15) {
var room = limit15 – currentStack;
var fill = Math.min(room, incomeRemaining);
tax += fill * 0.15;
incomeRemaining -= fill;
currentStack += fill;
}
if (incomeRemaining <= 0) return tax;
// Bucket 3: 20% Tax
// Anything remaining is taxed at 20%
tax += incomeRemaining * 0.20;
return tax;
}