Capital Gains Tax Calculator (2024 Estimate)
body {
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
line-height: 1.6;
color: #333;
max-width: 1200px;
margin: 0 auto;
padding: 20px;
background-color: #f9f9f9;
}
.calc-wrapper {
display: flex;
flex-wrap: wrap;
gap: 40px;
background: #fff;
padding: 30px;
border-radius: 12px;
box-shadow: 0 4px 12px rgba(0,0,0,0.1);
margin-bottom: 40px;
}
.calc-inputs {
flex: 1;
min-width: 300px;
}
.calc-results {
flex: 1;
min-width: 300px;
background-color: #f0f7ff;
padding: 25px;
border-radius: 8px;
border: 1px solid #d0e3ff;
}
h1 { text-align: center; color: #2c3e50; margin-bottom: 10px; }
h2 { color: #2c3e50; border-bottom: 2px solid #eee; padding-bottom: 10px; margin-top: 30px; }
h3 { margin-top: 0; color: #1a73e8; }
.form-group { margin-bottom: 20px; }
label { display: block; margin-bottom: 8px; font-weight: 600; color: #444; }
input, select {
width: 100%;
padding: 12px;
border: 1px solid #ddd;
border-radius: 6px;
font-size: 16px;
box-sizing: border-box;
}
input:focus, select:focus {
border-color: #1a73e8;
outline: none;
box-shadow: 0 0 0 3px rgba(26,115,232,0.2);
}
.btn-calc {
background-color: #1a73e8;
color: white;
border: none;
padding: 15px 30px;
font-size: 18px;
font-weight: bold;
border-radius: 6px;
cursor: pointer;
width: 100%;
transition: background 0.2s;
}
.btn-calc:hover { background-color: #1557b0; }
.result-row {
display: flex;
justify-content: space-between;
margin-bottom: 15px;
padding-bottom: 15px;
border-bottom: 1px solid #dee2e6;
}
.result-row:last-child { border-bottom: none; }
.result-label { font-weight: 600; color: #555; }
.result-value { font-weight: 700; font-size: 1.1em; }
.total-tax { color: #d32f2f; }
.net-profit { color: #2e7d32; font-size: 1.4em; }
.article-content {
background: #fff;
padding: 40px;
border-radius: 12px;
box-shadow: 0 2px 8px rgba(0,0,0,0.05);
}
.info-box {
background-color: #e8f0fe;
border-left: 4px solid #1a73e8;
padding: 15px;
margin: 20px 0;
}
table {
width: 100%;
border-collapse: collapse;
margin: 20px 0;
}
th, td {
padding: 12px;
border: 1px solid #ddd;
text-align: left;
}
th { background-color: #f8f9fa; font-weight: 700; }
@media (max-width: 768px) {
.calc-wrapper { flex-direction: column; padding: 20px; }
}
Capital Gains Tax Calculator
Estimate your federal and state tax liability on investment sales.
Results Breakdown
Total Capital Gain:
$0.00
Federal Tax:
$0.00
Net Investment Income Tax (NIIT):
$0.00
State Tax:
$0.00
Total Estimated Tax:
$0.00
After-Tax Profit:
$0.00
Understanding 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. This difference is known as your "capital gain." If you sell an asset for less than you bought it for, you have a capital loss, which can sometimes be used to offset gains.
Key Takeaway: The length of time you hold an asset before selling it significantly impacts your tax rate. Assets held for more than a year benefit from lower "Long-Term" tax rates.
Short-Term vs. Long-Term Capital Gains
The IRS distinguishes between assets held for short periods versus long periods:
- Short-Term Capital Gains: Assets held for one year or less. These are taxed as ordinary income, meaning they are added to your regular salary and taxed at your marginal tax bracket (ranging from 10% to 37%).
- Long-Term Capital Gains: Assets held for more than one year. These receive preferential tax treatment with rates of 0%, 15%, or 20%, depending on your taxable income.
2024 Long-Term Capital Gains Tax Brackets
For the 2024 tax year, long-term capital gains are taxed according to the following income thresholds:
| Tax Rate |
Single |
Married Filing Jointly |
Head of Household |
| 0% |
Up to $47,025 |
Up to $94,050 |
Up to $63,000 |
| 15% |
$47,026 – $518,900 |
$94,051 – $583,750 |
$63,001 – $551,350 |
| 20% |
Over $518,900 |
Over $583,750 |
Over $551,350 |
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
- $200,000 for Head of Household
This calculator automatically checks if your total income (Salary + Gain) triggers this additional tax.
How to Minimize Capital Gains Tax
- Hold for over a year: Waiting at least one year and one day before selling converts short-term gains into long-term gains, potentially saving you 10-20% in taxes.
- Tax-Loss Harvesting: Sell underperforming assets to realize a loss. This loss can offset your capital gains, lowering your total taxable amount.
- Use Tax-Advantaged Accounts: Trading within a 401(k) or IRA does not trigger capital gains tax at the time of sale.
function calculateTax() {
// 1. Get Inputs
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);
// Validation
if (isNaN(purchasePrice) || isNaN(salePrice) || isNaN(annualIncome)) {
alert("Please enter valid numbers for Purchase Price, Sale Price, and Annual Income.");
return;
}
if (isNaN(stateRate)) {
stateRate = 0;
}
// 2. Calculate Base Gain
var gain = salePrice – purchasePrice;
// If loss or break-even
if (gain <= 0) {
document.getElementById('displayGain').innerText = formatMoney(gain);
document.getElementById('displayFedTax').innerText = "$0.00";
document.getElementById('displayNiitTax').innerText = "$0.00";
document.getElementById('displayStateTax').innerText = "$0.00";
document.getElementById('displayTotalTax').innerText = "$0.00";
document.getElementById('displayNetProfit').innerText = formatMoney(gain); // Loss is the "profit"
return;
}
// 3. Define Thresholds (2024 Estimates)
// Format: { status: { rate0_limit, rate15_limit } }
// rate20 is anything above rate15_limit
var ltBrackets = {
single: { limit0: 47025, limit15: 518900 },
married: { limit0: 94050, limit15: 583750 },
head: { limit0: 63000, limit15: 551350 }
};
// NIIT Thresholds
var niitThresholds = {
single: 200000,
married: 250000,
head: 200000
};
// 4. Calculate Federal Tax
var fedTax = 0;
var totalIncome = annualIncome + gain;
if (holdingPeriod === 'short') {
// Short Term: Taxed as Ordinary Income
// Simplified Ordinary Income Bracket Logic for the GAIN portion only
// We assume the gain sits "on top" of annual income
fedTax = calculateOrdinaryTax(annualIncome, gain, filingStatus);
} else {
// Long Term: Taxed at 0%, 15%, 20%
var limits = ltBrackets[filingStatus];
var taxableGain = gain;
var incomeFloor = annualIncome;
// Part of gain in 0% bucket
var spaceIn0 = Math.max(0, limits.limit0 – incomeFloor);
var gainIn0 = Math.min(taxableGain, spaceIn0);
taxableGain -= gainIn0;
incomeFloor += gainIn0;
// Part of gain in 15% bucket
var spaceIn15 = Math.max(0, limits.limit15 – incomeFloor);
var gainIn15 = Math.min(taxableGain, spaceIn15);
taxableGain -= gainIn15;
// Remaining gain in 20% bucket
var gainIn20 = taxableGain;
fedTax = (gainIn0 * 0) + (gainIn15 * 0.15) + (gainIn20 * 0.20);
}
// 5. Calculate NIIT (3.8%)
// Applies to the lesser of: Net Investment Income (the gain) OR Excess of MAGI over threshold
var niitLimit = niitThresholds[filingStatus];
var magi = annualIncome + gain;
var excessIncome = Math.max(0, magi – niitLimit);
var amountSubjectToNiit = Math.min(gain, excessIncome);
var niitTax = amountSubjectToNiit * 0.038;
// 6. Calculate State Tax
var stateTax = gain * (stateRate / 100);
// 7. Totals
var totalTax = fedTax + niitTax + stateTax;
var netProfit = gain – totalTax;
// 8. Display Results
document.getElementById('displayGain').innerText = formatMoney(gain);
document.getElementById('displayFedTax').innerText = formatMoney(fedTax);
document.getElementById('displayNiitTax').innerText = formatMoney(niitTax);
document.getElementById('displayStateTax').innerText = formatMoney(stateTax);
document.getElementById('displayTotalTax').innerText = formatMoney(totalTax);
document.getElementById('displayNetProfit').innerText = formatMoney(netProfit);
}
function calculateOrdinaryTax(baseIncome, gainAmount, status) {
// 2024 Ordinary Income Brackets (Simplified function for calculation)
// Returns the tax SPECIFICALLY on the gain amount added on top of baseIncome
var brackets = {
single: [11600, 47150, 100525, 191950, 243725, 609350], // Limits for 10, 12, 22, 24, 32, 35. 37 is above last
married: [23200, 94300, 201050, 383900, 487450, 731200],
head: [16550, 63100, 100500, 191950, 243700, 609350]
};
var rates = [0.10, 0.12, 0.22, 0.24, 0.32, 0.35, 0.37];
var limits = brackets[status];
// Calculate tax on (baseIncome + gainAmount) – tax on (baseIncome)
function getTotalTax(income, limits, rates) {
var tax = 0;
var previousLimit = 0;
for (var i = 0; i limits[i]) {
tax += (limits[i] – previousLimit) * rates[i];
previousLimit = limits[i];
} else {
tax += (income – previousLimit) * rates[i];
return tax;
}
}
// Over last limit (37%)
tax += (income – previousLimit) * rates[rates.length – 1];
return tax;
}
var taxOnBase = getTotalTax(baseIncome, limits, rates);
var taxOnTotal = getTotalTax(baseIncome + gainAmount, limits, rates);
return taxOnTotal – taxOnBase;
}
function formatMoney(amount) {
return '$' + amount.toLocaleString('en-US', { minimumFractionDigits: 2, maximumFractionDigits: 2 });
}