Capital Gains Tax Calculator 2024 | Estimate Your Investment Taxes
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-container {
background: #ffffff;
border: 1px solid #e1e1e1;
border-radius: 8px;
box-shadow: 0 4px 6px rgba(0,0,0,0.05);
padding: 30px;
margin-bottom: 40px;
}
.calc-header {
text-align: center;
margin-bottom: 25px;
border-bottom: 2px solid #2ecc71;
padding-bottom: 15px;
}
.calc-header h2 {
margin: 0;
color: #2c3e50;
}
.form-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 20px;
}
@media (max-width: 768px) {
.form-grid {
grid-template-columns: 1fr;
}
}
.input-group {
margin-bottom: 15px;
}
.input-group label {
display: block;
font-weight: 600;
margin-bottom: 5px;
font-size: 0.95rem;
}
.input-group input, .input-group select {
width: 100%;
padding: 10px;
border: 1px solid #ccc;
border-radius: 4px;
font-size: 1rem;
box-sizing: border-box;
}
.input-group input:focus, .input-group select:focus {
border-color: #2ecc71;
outline: none;
box-shadow: 0 0 0 2px rgba(46, 204, 113, 0.2);
}
.btn-container {
grid-column: 1 / -1;
text-align: center;
margin-top: 10px;
}
button.calc-btn {
background-color: #2ecc71;
color: white;
border: none;
padding: 12px 30px;
font-size: 1.1rem;
border-radius: 5px;
cursor: pointer;
font-weight: bold;
transition: background-color 0.3s;
}
button.calc-btn:hover {
background-color: #27ae60;
}
#result-area {
margin-top: 30px;
display: none;
background-color: #f0fdf4;
border: 1px solid #bbf7d0;
border-radius: 6px;
padding: 20px;
}
.result-grid {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 15px;
text-align: center;
}
@media (max-width: 600px) {
.result-grid {
grid-template-columns: 1fr;
}
}
.result-item {
background: white;
padding: 15px;
border-radius: 6px;
box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}
.result-label {
font-size: 0.85rem;
text-transform: uppercase;
color: #666;
letter-spacing: 0.5px;
}
.result-value {
font-size: 1.5rem;
font-weight: 700;
color: #2c3e50;
margin-top: 5px;
}
.tax-breakdown {
margin-top: 20px;
font-size: 0.9rem;
color: #555;
border-top: 1px solid #bbf7d0;
padding-top: 15px;
}
.content-section {
background: white;
padding: 30px;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}
.content-section h2 {
color: #2c3e50;
margin-top: 0;
}
.content-section h3 {
color: #27ae60;
margin-top: 25px;
}
table {
width: 100%;
border-collapse: collapse;
margin: 20px 0;
}
table th, table td {
border: 1px solid #ddd;
padding: 12px;
text-align: left;
}
table th {
background-color: #f2f2f2;
}
.note {
font-size: 0.8rem;
color: #888;
font-style: italic;
}
Net Profit (After Tax)
$0.00
Understanding Capital Gains Tax
When you sell an asset—such as stocks, real estate, or cryptocurrency—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 primary factor in 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 taxed at your regular income tax bracket (ranging from 10% to 37%).
- Long-Term Capital Gains: Assets held for more than one year. These benefit from preferential tax rates of 0%, 15%, or 20%, depending on your total taxable income.
2024 Long-Term Capital Gains Tax Brackets
For the 2024 tax year, the income thresholds for long-term capital gains rates are as follows:
| Tax Rate |
Single Filers |
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 or Head of Household
- $250,000 for Married Filing Jointly
Our calculator automatically includes this surcharge if your income qualifies.
How to Lower Your Capital Gains Tax
1. Hold for over a year: The difference between ordinary income tax rates (up to 37%) and long-term rates (max 20%) is significant.
2. Tax-Loss Harvesting: You can use capital losses to offset capital gains. If your losses exceed your gains, you can deduct up to $3,000 of the excess loss from your ordinary income.
3. Use Tax-Advantaged Accounts: Trading within a 401(k) or IRA defers taxes until withdrawal (or eliminates them in the case of a Roth IRA).
function calculateCapitalGains() {
// Get input values
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 duration = document.getElementById('ownershipDuration').value;
// Validation
if (isNaN(purchasePrice) || isNaN(salePrice) || isNaN(income)) {
alert("Please enter valid numbers for prices and income.");
return;
}
// 1. Calculate Total Gain
var gain = salePrice – purchasePrice;
// If loss, no tax
if (gain <= 0) {
displayResult(gain, 0, 0, "No tax due on a capital loss.");
return;
}
var tax = 0;
var explanation = "";
var totalIncome = income + gain;
// 2. Logic for Short Term (Ordinary Income)
if (duration === "short") {
// Simplified Ordinary Income Tax Estimation (2024 Brackets)
// Note: This calculates the tax specifically ON THE GAIN, adding it on top of regular income (marginal)
// Tax Brackets 2024 (Single)
var brackets = [];
if (status === "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 if (status === "head") {
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 }
];
} else { // 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 }
];
}
// Calculate tax on income WITHOUT gain
var taxBase = calculateOrdinaryTax(income, brackets);
// Calculate tax on income WITH gain
var taxTotal = calculateOrdinaryTax(totalIncome, brackets);
tax = taxTotal – taxBase;
explanation = "Short-term gains are taxed as ordinary income. Your gain sits on top of your annual income, pushing it into applicable marginal tax brackets.";
}
// 3. Logic for Long Term (0%, 15%, 20%)
else {
// 2024 LTCG Thresholds
var limit0, limit15;
if (status === "married") {
limit0 = 94050;
limit15 = 583750;
} else if (status === "head") {
limit0 = 63000;
limit15 = 551350;
} else { // Single
limit0 = 47025;
limit15 = 518900;
}
// We need to see where the gain falls relative to the base income
var remainingGain = gain;
var currentIncomeLevel = income;
// Bucket 1: 0% Rate
if (currentIncomeLevel 0 && currentIncomeLevel 0) {
tax += remainingGain * 0.20;
}
explanation = "Long-term gains benefit from lower tax rates (0%, 15%, 20%) based on your total income.";
}
// 4. Net Investment Income Tax (NIIT) – 3.8%
// Thresholds: Single $200k, MFJ $250k, Head $200k
var niitThreshold = (status === "married") ? 250000 : 200000;
// NIIT applies to the lesser of: Net Investment Income (the gain) OR Amount MAGI exceeds threshold
if (totalIncome > niitThreshold) {
var excessIncome = totalIncome – niitThreshold;
var amountSubjectToNiit = Math.min(gain, excessIncome);
var niitTax = amountSubjectToNiit * 0.038;
tax += niitTax;
if (niitTax > 0) {
explanation += "
Note: Includes Net Investment Income Tax (NIIT) of 3.8% due to high income.";
}
}
displayResult(gain, tax, 1, explanation);
}
function calculateOrdinaryTax(incomeAmount, brackets) {
var tax = 0;
var previousLimit = 0;
for (var i = 0; i previousLimit) {
var taxableAmount = Math.min(incomeAmount, limit) – previousLimit;
tax += taxableAmount * rate;
previousLimit = limit;
} else {
break;
}
}
return tax;
}
function displayResult(gain, tax, taxRateType, text) {
var net = gain – tax;
// Formatting
document.getElementById('res-gain').innerText = formatCurrency(gain);
document.getElementById('res-tax').innerText = formatCurrency(tax);
document.getElementById('res-net').innerText = formatCurrency(net);
var effectiveRate = (gain > 0) ? ((tax / gain) * 100).toFixed(2) : "0.00";
document.getElementById('res-breakdown').innerHTML =
text + "
Effective Tax Rate: " + effectiveRate + "%";
document.getElementById('result-area').style.display = 'block';
}
function formatCurrency(num) {
return '$' + num.toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2});
}