Estimate your federal taxes on stock, real estate, or crypto sales.
$
$
$
Single
Married Filing Jointly
Head of Household
Married Filing Separately
More than 1 year (Long-Term)
1 year or less (Short-Term)
Total Capital Gain:$0.00
Tax Rate Applied:0%
Estimated Federal Tax:$0.00
Net Profit (After Tax):$0.00
function calculateCapitalGains() {
// 1. Get Input Values
var purchasePrice = parseFloat(document.getElementById('cgt-purchase-price').value);
var salePrice = parseFloat(document.getElementById('cgt-sale-price').value);
var annualIncome = parseFloat(document.getElementById('cgt-annual-income').value);
var filingStatus = document.getElementById('cgt-filing-status').value;
var duration = document.getElementById('cgt-duration').value;
// 2. Validate Inputs
if (isNaN(purchasePrice) || isNaN(salePrice) || isNaN(annualIncome)) {
alert("Please enter valid numbers for prices and income.");
return;
}
// 3. Calculate Gross Gain
var grossGain = salePrice – purchasePrice;
// Variables for calculations
var taxRate = 0;
var taxAmount = 0;
var netProfit = 0;
var rateText = "";
// 4. Handle Loss or Zero Gain
if (grossGain <= 0) {
taxAmount = 0;
taxRate = 0;
netProfit = grossGain;
rateText = "N/A (Loss)";
} else {
// 5. Determine Tax Rate based on Duration and Income Brackets (2024 Estimates)
if (duration === 'short') {
// Short-Term: Taxed as Ordinary Income
// Simplified marginal rate approximation based on 2024 brackets
// Note: This calculates the marginal rate of the total income, a standard estimation method for these tools.
var totalIncomeForBracket = annualIncome + grossGain; // Capital gains stack on top of income
if (filingStatus === 'single') {
if (totalIncomeForBracket <= 11600) taxRate = 0.10;
else if (totalIncomeForBracket <= 47150) taxRate = 0.12;
else if (totalIncomeForBracket <= 100525) taxRate = 0.22;
else if (totalIncomeForBracket <= 191950) taxRate = 0.24;
else if (totalIncomeForBracket <= 243725) taxRate = 0.32;
else if (totalIncomeForBracket <= 609350) taxRate = 0.35;
else taxRate = 0.37;
} else if (filingStatus === 'married_joint') {
if (totalIncomeForBracket <= 23200) taxRate = 0.10;
else if (totalIncomeForBracket <= 94300) taxRate = 0.12;
else if (totalIncomeForBracket <= 201050) taxRate = 0.22;
else if (totalIncomeForBracket <= 383900) taxRate = 0.24;
else if (totalIncomeForBracket <= 487450) taxRate = 0.32;
else if (totalIncomeForBracket <= 731200) taxRate = 0.35;
else taxRate = 0.37;
} else if (filingStatus === 'head_household') {
if (totalIncomeForBracket <= 16550) taxRate = 0.10;
else if (totalIncomeForBracket <= 63100) taxRate = 0.12;
else if (totalIncomeForBracket <= 100500) taxRate = 0.22;
else if (totalIncomeForBracket <= 191950) taxRate = 0.24;
else if (totalIncomeForBracket <= 243700) taxRate = 0.32;
else if (totalIncomeForBracket <= 609350) taxRate = 0.35;
else taxRate = 0.37;
} else { // Married Separate
if (totalIncomeForBracket <= 11600) taxRate = 0.10;
else if (totalIncomeForBracket <= 47150) taxRate = 0.12;
else if (totalIncomeForBracket <= 100525) taxRate = 0.22;
else if (totalIncomeForBracket <= 191950) taxRate = 0.24;
else if (totalIncomeForBracket <= 243725) taxRate = 0.32;
else if (totalIncomeForBracket <= 365600) taxRate = 0.35;
else taxRate = 0.37;
}
rateText = (taxRate * 100).toFixed(1) + "% (Short-Term)";
} else {
// Long-Term: Preferential Tax Rates (0%, 15%, 20%)
// Based on Taxable Income (including the gain)
var taxableIncome = annualIncome; // Usually brackets are based on taxable income
if (filingStatus === 'single') {
if (taxableIncome <= 47025) taxRate = 0.00;
else if (taxableIncome <= 518900) taxRate = 0.15;
else taxRate = 0.20;
} else if (filingStatus === 'married_joint') {
if (taxableIncome <= 94050) taxRate = 0.00;
else if (taxableIncome <= 583750) taxRate = 0.15;
else taxRate = 0.20;
} else if (filingStatus === 'head_household') {
if (taxableIncome <= 63000) taxRate = 0.00;
else if (taxableIncome <= 551350) taxRate = 0.15;
else taxRate = 0.20;
} else { // Married Separate
if (taxableIncome <= 47025) taxRate = 0.00;
else if (taxableIncome Threshold. Thresholds: $200k (Single), $250k (Married Joint), $125k (Married Sep)
var niitThreshold = 200000;
if (filingStatus === 'married_joint') niitThreshold = 250000;
if (filingStatus === 'married_separate') niitThreshold = 125000;
// Very simplified NIIT check: if income + gain > threshold
if ((annualIncome + grossGain) > niitThreshold) {
// NIIT is lesser of Net Investment Income OR (MAGI – Threshold)
// For this calculator, we add a simplified surtax note
var niitAmount = grossGain * 0.038;
taxAmount += niitAmount;
rateText += " + 3.8% NIIT";
}
netProfit = grossGain – taxAmount;
}
// 6. Formatting Helpers
var formatter = new Intl.NumberFormat('en-US', {
style: 'currency',
currency: 'USD',
});
// 7. Update DOM
document.getElementById('cgt-display-gain').innerText = formatter.format(grossGain);
document.getElementById('cgt-display-rate').innerText = rateText;
document.getElementById('cgt-display-tax').innerText = formatter.format(taxAmount);
document.getElementById('cgt-display-net').innerText = formatter.format(netProfit);
// Show results
document.getElementById('cgt-results-box').classList.add('visible');
}
Understanding Capital Gains Tax in 2024
When you sell an asset for more than you paid for it, the profit is known as a capital gain. The Internal Revenue Service (IRS) taxes these profits, but the rate you pay depends heavily on how long you held the asset before selling it and your annual income level. Use the Capital Gains Tax Calculator above to estimate your potential liability.
Key Rule: Assets held for more than one year qualify for long-term capital gains rates, which are significantly lower than ordinary income tax rates.
Short-Term vs. Long-Term Capital Gains
The duration of ownership is the single most important factor in calculating your tax bill:
Short-Term Capital Gains: If you sell an asset after holding it for one year or less, the profit is taxed as ordinary income. This means it is added to your salary and other earnings, potentially pushing you into a higher tax bracket (up to 37%).
Long-Term Capital Gains: If you hold the asset for more than one year, you qualify for preferential tax rates of 0%, 15%, or 20%, depending on your filing status and taxable income.
How Capital Gains Tax is Calculated
The formula for capital gains is relatively straightforward:
Determine Cost Basis: This is usually the purchase price plus any fees (like commissions) paid to acquire the asset.
Calculate Gross Gain: Subtract the Cost Basis from the Sale Price.
Apply Tax Rate: Based on the holding period (short vs. long term) and your total taxable income, apply the relevant percentage to the Gross Gain.
Example Scenario
Imagine you purchased stock for $5,000 and sold it two years later for $15,000. Your capital gain is $10,000.
Since you held it for more than a year, it is a Long-Term gain. If you are a single filer with $60,000 in annual income, you fall into the 15% long-term capital gains bracket. Your tax would be roughly $1,500 ($10,000 × 15%), leaving you with a net profit of $8,500.
Net Investment Income Tax (NIIT)
High-income earners may be subject to an additional 3.8% tax known as the Net Investment Income Tax. This generally applies if your modified adjusted gross income exceeds $200,000 for single filers or $250,000 for married couples filing jointly.
Strategies to Minimize Capital Gains Tax
Hold for over a year: Waiting just one day past the one-year mark can cut your tax rate almost in half.
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.
Utilize Tax-Advantaged Accounts: Trading within a 401(k) or IRA does not trigger immediate capital gains taxes.