Estimate your federal and state tax liability on investment sales.
Less than 1 year (Short Term)
More than 1 year (Long Term)
Single
Married Filing Jointly
Head of Household
Total Capital Gain:$0.00
Federal Tax Estimated:$0.00
Net Investment Income Tax (NIIT):$0.00
State Tax Estimated:$0.00
Total Estimated Tax:$0.00
Net Profit After Tax:$0.00
*Figures are estimates based on projected 2025 tax brackets. Consult a tax professional for exact figures.
function calculateCapitalGains() {
var purchasePrice = parseFloat(document.getElementById("purchasePrice").value);
var salePrice = parseFloat(document.getElementById("salePrice").value);
var annualIncome = parseFloat(document.getElementById("annualIncome").value);
var filingStatus = document.getElementById("filingStatus").value;
var holdingPeriod = document.getElementById("holdingPeriod").value;
var stateRate = parseFloat(document.getElementById("stateTaxRate").value);
if (isNaN(purchasePrice) || isNaN(salePrice) || isNaN(annualIncome)) {
alert("Please enter valid numbers for prices and income.");
return;
}
if (isNaN(stateRate)) {
stateRate = 0;
}
var gain = salePrice – purchasePrice;
var federalTax = 0;
var niitTax = 0;
// NIIT Calculation (3.8% if MAGI above threshold)
// Thresholds: Single 200k, Married 250k, Head 200k
var niitThreshold = (filingStatus === "married") ? 250000 : 200000;
var totalIncome = annualIncome + gain;
if (totalIncome > niitThreshold) {
var amountSubjectToNiit = Math.min(totalIncome – niitThreshold, gain);
if (amountSubjectToNiit > 0) {
niitTax = amountSubjectToNiit * 0.038;
}
}
if (gain <= 0) {
// Loss
federalTax = 0;
niitTax = 0;
} else {
if (holdingPeriod === "short") {
// Short Term Logic (Ordinary Income Brackets 2024/2025 Est)
// Simplified: We calculate tax on (Income + Gain) minus tax on (Income)
federalTax = calculateOrdinaryTax(annualIncome + gain, filingStatus) – calculateOrdinaryTax(annualIncome, filingStatus);
} else {
// Long Term Logic (0%, 15%, 20% buckets)
// Brackets 2024 (approximate)
var limit0, limit15;
if (filingStatus === "single") {
limit0 = 47025;
limit15 = 518900;
} else if (filingStatus === "married") {
limit0 = 94050;
limit15 = 583750;
} else { // head
limit0 = 63000;
limit15 = 551350;
}
// The gain stacks on top of ordinary income
var incomeFloor = annualIncome;
var incomeCeiling = annualIncome + gain;
// Calculate amount in 0% bucket
var amountIn0 = 0;
if (incomeFloor 0) {
// The floor for this chunk is now Max(income, limit0)
var floor15 = Math.max(incomeFloor, limit0);
if (floor15 0) ? (gain * (stateRate / 100)) : 0;
var totalTax = federalTax + niitTax + stateTax;
var netProfit = gain – totalTax;
document.getElementById("displayGain").innerText = formatCurrency(gain);
document.getElementById("displayFedTax").innerText = formatCurrency(federalTax);
document.getElementById("displayNiitTax").innerText = formatCurrency(niitTax);
document.getElementById("displayStateTax").innerText = formatCurrency(stateTax);
document.getElementById("displayTotalTax").innerText = formatCurrency(totalTax);
document.getElementById("displayNetProfit").innerText = formatCurrency(netProfit);
document.getElementById("cgtResult").style.display = "block";
}
function calculateOrdinaryTax(income, status) {
// Simplified Ordinary Income Brackets 2024
// Returns total tax for a given income
var brackets;
if (status === "single") {
brackets = [
{ cap: 11600, rate: 0.10 },
{ cap: 47150, rate: 0.12 },
{ cap: 100525, rate: 0.22 },
{ cap: 191950, rate: 0.24 },
{ cap: 243725, rate: 0.32 },
{ cap: 609350, rate: 0.35 },
{ cap: Infinity, rate: 0.37 }
];
} else if (status === "married") {
brackets = [
{ cap: 23200, rate: 0.10 },
{ cap: 94300, rate: 0.12 },
{ cap: 201050, rate: 0.22 },
{ cap: 383900, rate: 0.24 },
{ cap: 487450, rate: 0.32 },
{ cap: 731200, rate: 0.35 },
{ cap: Infinity, rate: 0.37 }
];
} else { // head
brackets = [
{ cap: 16550, rate: 0.10 },
{ cap: 63100, rate: 0.12 },
{ cap: 100500, rate: 0.22 },
{ cap: 191950, rate: 0.24 },
{ cap: 243700, rate: 0.32 },
{ cap: 609350, rate: 0.35 },
{ cap: Infinity, rate: 0.37 }
];
}
var tax = 0;
var previousCap = 0;
for (var i = 0; i currentCap) {
tax += (currentCap – previousCap) * rate;
previousCap = currentCap;
} else {
tax += (income – previousCap) * rate;
break;
}
}
return tax;
}
function formatCurrency(num) {
return "$" + num.toFixed(2).replace(/\d(?=(\d{3})+\.)/g, '$&,');
}
Understanding Capital Gains Tax
When you sell an asset—whether it's stocks, real estate, or a business—for more than you paid for it, the profit is considered a "capital gain." The IRS taxes these gains differently depending on how long you held the asset before selling.
Short-Term vs. Long-Term Capital Gains
The duration of ownership is the most critical factor in calculating your tax liability:
Short-Term: Assets held for one year or less. These are taxed at your ordinary income tax rate, which can be as high as 37% for high earners.
Long-Term: Assets held for more than one year. These benefit from preferential tax rates of 0%, 15%, or 20%, depending on your total taxable income.
Net Investment Income Tax (NIIT)
High-income earners may 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
$250,000 for Married Filing Jointly
This surtax applies to the lesser of your net investment income or the amount by which your MAGI exceeds the threshold.
How to Reduce Capital Gains Tax
Hold for over a year: Waiting even one day past the one-year mark can significantly reduce your tax rate.
Tax-Loss Harvesting: You can offset capital gains by selling underperforming assets at a loss. Up to $3,000 of excess losses can be deducted from ordinary income annually.
Utilize Tax-Advantaged Accounts: Trading within a 401(k) or IRA does not trigger immediate capital gains taxes.
1031 Exchange (Real Estate): For investment properties, you can defer taxes by reinvesting the proceeds into a "like-kind" property.
Frequently Asked Questions
Does this calculator include state taxes?
Yes, you can input your specific state tax rate. However, note that some states treat capital gains as ordinary income, while others offer special treatment or have no income tax at all.
What is the Cost Basis?
The cost basis is generally the original purchase price of the asset, plus any fees (like commissions) paid to acquire it. For real estate, it can also include the cost of improvements made to the property.
How are the tax brackets determined?
The long-term capital gains tax rate (0%, 15%, or 20%) is based on your total taxable income, not just the gain itself. The gain sits "on top" of your ordinary income to determine which bracket it falls into.