When you sell an investment, like stocks, for more than you paid for it, you realize a capital gain. This profit is subject to capital gains tax. The tax rate you pay depends on how long you held the investment and your income level.
Short-Term vs. Long-Term Capital Gains
Short-Term Capital Gains: If you hold an asset for one year or less before selling it, the profit is considered a short-term capital gain. These gains are taxed at your ordinary income tax rate.
Long-Term Capital Gains: If you hold an asset for more than one year before selling it, the profit is considered a long-term capital gain. These are generally taxed at lower rates than ordinary income.
Current Long-Term Capital Gains Tax Rates (2023/2024 – Consult your tax advisor for specific year and personal situation)
The long-term capital gains tax rates depend on your taxable income and filing status. For 2023/2024, the rates are typically:
0% for lower income brackets.
15% for middle income brackets.
20% for higher income brackets.
These thresholds change annually and vary for Single filers versus Married Filing Jointly.
How the Calculator Works
This calculator estimates your capital gains tax based on the following steps:
Calculate Total Cost Basis: This is the total amount you paid for the shares, including any commissions or fees.
Total Cost Basis = Purchase Price per Share * Number of Shares
Calculate Total Sale Proceeds: This is the total amount you received from selling the shares.
Total Sale Proceeds = Sale Price per Share * Number of Shares
Calculate Capital Gain: The difference between your sale proceeds and your cost basis.
Capital Gain = Total Sale Proceeds - Total Cost Basis
Determine Holding Period: The number of days you owned the stock. If over 365 days, it's long-term; otherwise, it's short-term.
Determine Applicable Tax Rate:
If Short-Term: The rate is your *ordinary income tax rate*. This calculator uses a placeholder rate (e.g., 24%) for short-term gains, as your actual rate depends on your total income.
If Long-Term: The rate depends on the capital gain amount and your filing status. This calculator uses simplified rate tiers based on common thresholds.
Calculate Capital Gains Tax:Capital Gains Tax = Capital Gain * Applicable Tax Rate
Disclaimer: This calculator is for educational purposes only and does not constitute tax advice. Tax laws are complex and subject to change. Always consult with a qualified tax professional for advice specific to your financial situation.
function calculateCapitalGainsTax() {
var purchasePrice = parseFloat(document.getElementById("purchasePrice").value);
var numberOfShares = parseInt(document.getElementById("numberOfShares").value);
var salePrice = parseFloat(document.getElementById("salePrice").value);
var holdingPeriod = parseInt(document.getElementById("holdingPeriod").value);
var filingStatus = document.getElementById("filingStatus").value;
var totalGain = 0;
var capitalGainsTax = 0;
var taxRate = 0;
var applicableLongTermRate = 0;
// Input validation
if (isNaN(purchasePrice) || isNaN(numberOfShares) || isNaN(salePrice) || isNaN(holdingPeriod) ||
purchasePrice < 0 || numberOfShares < 0 || salePrice < 0 || holdingPeriod < 0) {
document.getElementById("totalGain").textContent = "Invalid input. Please enter valid positive numbers.";
document.getElementById("capitalGainsTax").textContent = "";
document.getElementById("taxRate").textContent = "";
return;
}
var totalCostBasis = purchasePrice * numberOfShares;
var totalSaleProceeds = salePrice * numberOfShares;
totalGain = totalSaleProceeds – totalCostBasis;
if (totalGain 365) {
// Long-Term Capital Gains
// Simplified tax brackets for illustration. Actual brackets vary by year and depend on total income.
// Example thresholds (these are rough and subject to change, consult IRS or tax professional):
var singleLongTermThresholds = {
"0": 44625, // 0% rate up to this income level
"15": 492300, // 15% rate up to this income level
"20": Infinity // 20% rate above this income level
};
var marriedJointlyLongTermThresholds = {
"0": 89250,
"15": 984600,
"20": Infinity
};
var effectiveLongTermRate = 0;
var ratePercentage = 0;
if (filingStatus === "single") {
if (totalGain <= singleLongTermThresholds["0"]) {
effectiveLongTermRate = 0.00;
ratePercentage = 0;
} else if (totalGain <= singleLongTermThresholds["15"]) {
effectiveLongTermRate = 0.15;
ratePercentage = 15;
} else {
effectiveLongTermRate = 0.20;
ratePercentage = 20;
}
} else { // married_filing_jointly
if (totalGain <= marriedJointlyLongTermThresholds["0"]) {
effectiveLongTermRate = 0.00;
ratePercentage = 0;
} else if (totalGain <= marriedJointlyLongTermThresholds["15"]) {
effectiveLongTermRate = 0.15;
ratePercentage = 15;
} else {
effectiveLongTermRate = 0.20;
ratePercentage = 20;
}
}
taxRate = effectiveLongTermRate;
applicableLongTermRate = ratePercentage;
} else {
// Short-Term Capital Gains
// Short-term gains are taxed at ordinary income tax rates.
// Since we don't have the user's total income, we'll use a representative rate.
// For demonstration, let's assume an ordinary income tax rate of 24%.
// A more robust calculator would require total income input.
taxRate = 0.24; // Placeholder for ordinary income tax rate
applicableLongTermRate = 24; // Display as percentage
}
capitalGainsTax = totalGain * taxRate;
document.getElementById("totalGain").textContent = totalGain.toFixed(2);
document.getElementById("capitalGainsTax").textContent = capitalGainsTax.toFixed(2);
document.getElementById("taxRate").textContent = applicableLongTermRate.toFixed(1) + "%";
}