Estimate your federal tax liability on stock, real estate, or crypto profits.
$
$
$
Single
Married Filing Jointly
Head of Household
Less than 1 Year (Short Term)
More than 1 Year (Long Term)
Total Capital Gain:$0.00
Tax Type Applied:Long Term
Estimated Federal Tax Rate:0%
Estimated Tax Owed:$0.00
Net Profit (After Tax):$0.00
Understanding Capital Gains Tax
When you sell an asset—such as stocks, bonds, real estate, or cryptocurrency—for more than you paid for it, the profit is considered a capital gain. The federal government taxes this profit, but the rate depends heavily on how long you held the asset and your total annual income.
Short-Term vs. Long-Term Capital Gains
The duration of ownership is the most critical factor in calculating your tax liability:
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 according to your standard 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 income level.
Current Federal Tax Rates (2024 Estimates)
For long-term assets, the tax rate is determined by your taxable income and filing status:
0% Rate: Applied to individuals with lower taxable income (e.g., up to roughly $47,025 for singles).
15% Rate: The most common bracket, applied to incomes between roughly $47,025 and $518,900 for singles.
20% Rate: Applied to high-income earners exceeding the 15% threshold.
Note: High earners may also be subject to an additional 3.8% Net Investment Income Tax (NIIT).
How to Calculate Your Gains
The formula for capital gains is straightforward:
Capital Gain = Final Sale Price – Cost Basis (Purchase Price + Fees)
If the result is negative, you have a capital loss, which can potentially be used to offset other gains or up to $3,000 of ordinary income per year.
Strategies to Minimize Capital Gains Tax
Investors often use specific strategies to reduce their tax burden:
Hold for over a year: Waiting for the 366th day to sell can significantly drop your tax rate from ordinary income levels (up to 37%) to the long-term rate (usually 15%).
Tax-Loss Harvesting: Selling assets that are at a loss to offset gains realized from other assets.
Utilize Tax-Advantaged Accounts: Trading within a 401(k) or IRA defers or eliminates capital gains taxes until withdrawal.
function calculateCapitalGains() {
// 1. Get input values
var buyPrice = parseFloat(document.getElementById('purchasePrice').value);
var sellPrice = parseFloat(document.getElementById('salePrice').value);
var income = parseFloat(document.getElementById('annualIncome').value);
var status = document.getElementById('filingStatus').value;
var duration = document.getElementById('ownershipDuration').value;
// 2. Validate inputs
if (isNaN(buyPrice) || isNaN(sellPrice) || isNaN(income)) {
alert("Please enter valid numbers for prices and income.");
return;
}
// 3. Calculate Raw Gain
var gain = sellPrice – buyPrice;
var taxOwed = 0;
var taxRateDisplay = "0%";
var taxTypeDisplay = duration === 'short' ? "Short Term (Ordinary Income)" : "Long Term";
// If there is a loss or no gain
if (gain <= 0) {
taxOwed = 0;
taxRateDisplay = "N/A (Loss)";
} else {
// 4. Calculate Tax based on Duration
if (duration === 'short') {
// Short Term: Taxed as Ordinary Income
// Using simplified 2024 brackets for estimation
// Note: This logic assumes the gain sits on top of the annual income provided.
// For a perfect marginal calculation, we'd need a complex loop, but for a standard estimator,
// determining the bracket of the total income (Income + Gain) is a standard approximation method.
var totalIncome = income + gain;
var rate = 0;
// Simplified standard brackets (Single/Married)
if (status === 'married') {
if (totalIncome <= 23200) rate = 0.10;
else if (totalIncome <= 94300) rate = 0.12;
else if (totalIncome <= 201050) rate = 0.22;
else if (totalIncome <= 383900) rate = 0.24;
else if (totalIncome <= 487450) rate = 0.32;
else if (totalIncome <= 731200) rate = 0.35;
else rate = 0.37;
} else {
// Single or Head of Household (Approximated to Single for simplicity in this specific tool)
if (totalIncome <= 11600) rate = 0.10;
else if (totalIncome <= 47150) rate = 0.12;
else if (totalIncome <= 100525) rate = 0.22;
else if (totalIncome <= 191950) rate = 0.24;
else if (totalIncome <= 243725) rate = 0.32;
else if (totalIncome <= 609350) rate = 0.35;
else rate = 0.37;
}
taxOwed = gain * rate;
taxRateDisplay = (rate * 100).toFixed(1) + "% (Marginal)";
} else {
// Long Term: Preferential Rates (0%, 15%, 20%)
// 2024 Thresholds
var rate = 0;
if (status === 'married') {
if (income <= 94050) rate = 0;
else if (income <= 583750) rate = 0.15;
else rate = 0.20;
} else {
// Single
if (income <= 47025) rate = 0;
else if (income niitThreshold) {
rate += 0.038;
taxRateDisplay = ((rate – 0.038) * 100).toFixed(0) + "% + 3.8% NIIT";
} else {
taxRateDisplay = (rate * 100).toFixed(0) + "%";
}
taxOwed = gain * rate;
}
}
// 5. Calculate Net Profit
var netProfit = gain – taxOwed;
// 6. Format and Display Results
var formatter = new Intl.NumberFormat('en-US', {
style: 'currency',
currency: 'USD',
});
document.getElementById('displayGain').innerText = formatter.format(gain);
document.getElementById('displayType').innerText = taxTypeDisplay;
document.getElementById('displayRate').innerText = taxRateDisplay;
document.getElementById('displayTax').innerText = formatter.format(taxOwed);
document.getElementById('displayNet').innerText = formatter.format(netProfit);
// Show result div
document.getElementById('cgtResult').style.display = 'block';
}