Include salary, wages, and other income excluding this gain.
Single
Married Filing Jointly
Head of Household
Total Capital Gain:$0.00
Applicable Tax Rate:0%
Estimated Tax Owed:$0.00
Net Profit (After Tax):$0.00
function calculateCapitalGains() {
// Get Inputs
var purchasePrice = parseFloat(document.getElementById('purchasePrice').value);
var salePrice = parseFloat(document.getElementById('salePrice').value);
var income = parseFloat(document.getElementById('annualIncome').value);
var status = document.getElementById('filingStatus').value;
var isLongTerm = document.getElementById('durationLong').checked;
// Validation
if (isNaN(purchasePrice) || isNaN(salePrice) || isNaN(income)) {
alert("Please enter valid numbers for prices and income.");
return;
}
// Logic
var gain = salePrice – purchasePrice;
var taxRate = 0;
var taxAmount = 0;
var niitThreshold = 0;
// Display Logic for Loss
if (gain <= 0) {
document.getElementById('displayGain').innerText = "-$" + Math.abs(gain).toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2});
document.getElementById('displayRate').innerText = "0% (Capital Loss)";
document.getElementById('displayTax').innerText = "$0.00";
document.getElementById('displayNet').innerText = "-$" + Math.abs(gain).toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2});
document.getElementById('results-area').style.display = "block";
return;
}
// Tax Logic
if (!isLongTerm) {
// Short Term Capital Gains (Taxed as Ordinary Income)
// Using 2024 Tax Brackets Estimate for simplicity
// This is a marginal rate estimation based on total income + gain
var totalIncome = income + gain;
// Simplified marginal rate lookup based on Single/Married
if (status === 'married') {
if (totalIncome <= 23200) taxRate = 0.10;
else if (totalIncome <= 94300) taxRate = 0.12;
else if (totalIncome <= 201050) taxRate = 0.22;
else if (totalIncome <= 383900) taxRate = 0.24;
else if (totalIncome <= 487450) taxRate = 0.32;
else if (totalIncome <= 731200) taxRate = 0.35;
else taxRate = 0.37;
} else {
// Single and Head of Household (approximated to Single for calculator simplicity in this demo)
if (totalIncome <= 11600) taxRate = 0.10;
else if (totalIncome <= 47150) taxRate = 0.12;
else if (totalIncome <= 100525) taxRate = 0.22;
else if (totalIncome <= 191950) taxRate = 0.24;
else if (totalIncome <= 243725) taxRate = 0.32;
else if (totalIncome <= 609350) taxRate = 0.35;
else taxRate = 0.37;
}
} else {
// Long Term Capital Gains (0%, 15%, 20%)
// 2024 Thresholds
var rate0, rate15;
if (status === 'single') {
rate0 = 47025;
rate15 = 518900;
} else if (status === 'married') {
rate0 = 94050;
rate15 = 583750;
} else { // Head of household
rate0 = 63000;
rate15 = 551350;
}
if (income < rate0) {
taxRate = 0.0;
} else if (income niitLimit) {
var niitAmount = gain * 0.038;
taxAmount += niitAmount;
// Adjust displayed effective rate to reflect NIIT
taxRate += 0.038;
}
var netProfit = gain – taxAmount;
// Update DOM
document.getElementById('displayGain').innerText = "$" + gain.toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2});
document.getElementById('displayRate').innerText = (taxRate * 100).toFixed(1) + "%";
document.getElementById('displayTax').innerText = "$" + taxAmount.toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2});
document.getElementById('displayNet').innerText = "$" + netProfit.toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2});
document.getElementById('results-area').style.display = "block";
}
Comprehensive Guide to Capital Gains Tax
Understanding how much you owe the government after selling an asset is crucial for effective financial planning. Whether you are selling stocks, real estate, or a business, the Capital Gains Tax Calculator above helps you estimate your potential tax liability based on the latest 2024 tax brackets.
What is 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. If you sell an asset for more than you paid for it, you have a "capital gain," and that profit is taxable.
Conversely, if you sell for less than you paid, you have a "capital loss," which can sometimes be used to offset other gains or lower your taxable income.
Short-Term vs. Long-Term Capital Gains
The duration for which you hold an asset significantly impacts the tax rate applied to your profit:
Short-Term Capital Gains: This applies to assets held for one year or less. Profits are taxed as ordinary income, meaning they are subject to your standard federal income tax brackets, which can range from 10% to 37% depending on your total annual income.
Long-Term Capital Gains: This applies to assets held for more than one year. These are generally taxed at preferential rates of 0%, 15%, or 20%, which are significantly lower than ordinary income tax rates for most high earners.
How the Tax is Calculated
The calculation involves several steps:
Determine the Basis: This is usually your purchase price plus any commissions or fees paid.
Determine the Realized Amount: This is the sale price minus any selling costs.
Calculate the Gain: Subtract the Basis from the Realized Amount.
Apply the Tax Rate: Based on your filing status, income level, and holding period, the appropriate percentage is applied to the gain.
Note: High-income earners may also be subject to an additional 3.8% Net Investment Income Tax (NIIT).
Strategies to Minimize Capital Gains Tax
Investors often use specific strategies to reduce their tax burden:
Hold for over a year: Waiting until the 366th day to sell can cut your tax rate by nearly half.
Tax-Loss Harvesting: Selling underperforming assets at a loss can offset gains realized elsewhere in your portfolio.
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).
Does this calculator include state taxes?
No, this calculator estimates Federal Capital Gains Tax only. Most states also tax capital gains as ordinary income, so your total liability may be higher depending on where you live.
What is the Net Investment Income Tax (NIIT)?
The NIIT is an additional 3.8% tax that applies to individuals with a modified adjusted gross income above $200,000 (single) or $250,000 (married filing jointly). It applies to the lesser of your net investment income or the amount by which your income exceeds the threshold.
Can I deduct capital losses?
Yes. If your capital losses exceed your capital gains, you can deduct the difference on your tax return, up to $3,000 per year ($1,500 if married filing separately). Losses beyond this limit can be carried forward to future years.