Capital Gains on Stock Sale Calculator
Estimate your gain or loss, holding period, federal tax impact, Net Investment Income Tax, state tax, and after-tax proceeds in seconds.
Your Results
Enter your stock sale details, then click Calculate to see gain type, taxes, and after-tax proceeds.
How to Calculate Capital Gains on Stock Sale: A Complete Expert Guide
If you sell stock for more than your tax basis, you usually create a capital gain. If you sell for less, you create a capital loss. The core math is straightforward, but the tax result depends on holding period, filing status, income level, prior losses, and whether your gain is short-term or long-term. This guide walks you through the exact process so you can estimate your taxes with confidence before you place a trade.
At a high level, the formula is simple: Capital Gain (or Loss) = Net Sale Proceeds – Adjusted Cost Basis. The challenge is correctly defining each component. Small details like commissions, reinvested dividends, stock splits, and specific lot identification can materially change the final number.
Step 1: Calculate Net Sale Proceeds
Start with gross sale value and subtract selling expenses:
- Gross Sale Value = Shares Sold × Sale Price per Share
- Net Sale Proceeds = Gross Sale Value – Broker Commissions – Transaction Fees
Even in a low-commission environment, fees can still appear through regulatory charges, platform fees, or other transaction costs. Keep your broker confirmation statements because tax reporting should tie back to your official records.
Step 2: Determine Adjusted Cost Basis
Cost basis starts with what you paid for the shares and then gets adjusted for specific events. In many cases:
- Initial Basis = Shares Purchased × Purchase Price per Share
- Add purchase commissions and fees.
- Add reinvested dividends that were taxed in prior years.
- Adjust for corporate actions such as splits, spin-offs, and mergers when applicable.
Your adjusted basis is what the IRS effectively treats as your investment amount. If basis is understated, you can overpay tax. If overstated, you can underpay and risk penalties. Precision matters.
Step 3: Compute Raw Capital Gain or Loss
Once you have proceeds and basis:
- Compute net sale proceeds.
- Compute adjusted basis.
- Subtract basis from proceeds.
If the result is positive, you have a gain. If negative, you have a loss. Next, classify the holding period because that drives tax rate treatment.
Step 4: Classify the Gain as Short-Term or Long-Term
Holding period generally starts the day after acquisition and includes the day of sale. In practical planning terms:
- Short-term gain: held one year or less, taxed at ordinary income rates.
- Long-term gain: held more than one year, taxed at preferential long-term capital gains rates (0%, 15%, or 20% at the federal level).
Two investors with the same dollar gain can owe very different taxes solely based on whether the holding period crossed the one-year threshold.
Federal Long-Term Capital Gains Rates (2024 Data)
The IRS long-term capital gains framework is based on taxable income and filing status. The table below summarizes commonly referenced federal thresholds for tax year 2024.
| Filing Status | 0% Rate up to | 15% Rate up to | 20% Rate Above |
|---|---|---|---|
| Single | $47,025 | $518,900 | Over $518,900 |
| Married Filing Jointly | $94,050 | $583,750 | Over $583,750 |
| Married Filing Separately | $47,025 | $291,850 | Over $291,850 |
| Head of Household | $63,000 | $551,350 | Over $551,350 |
These are federal thresholds and can change annually for inflation adjustments. Always verify final numbers in IRS resources for your specific filing year.
Ordinary Tax Brackets Matter for Short-Term Gains (2024 Data)
Short-term capital gains are generally taxed like wages and other ordinary income. That means your marginal bracket can increase the effective tax on short-term trading profits.
| Filing Status | Top of 22% Bracket | Top of 24% Bracket | Top of 32% Bracket | Top of 35% Bracket |
|---|---|---|---|---|
| Single | $100,525 | $191,950 | $243,725 | $609,350 |
| Married Filing Jointly | $201,050 | $383,900 | $487,450 | $731,200 |
| Married Filing Separately | $100,525 | $191,950 | $243,725 | $365,600 |
| Head of Household | $100,500 | $191,950 | $243,700 | $609,350 |
Net Investment Income Tax (NIIT): The 3.8% Layer
Higher-income taxpayers may owe an extra 3.8% NIIT on net investment income. This is often missed in quick estimates. NIIT thresholds are not indexed in the same way as other tax amounts, and for many taxpayers they are:
- Single or Head of Household: $200,000
- Married Filing Jointly: $250,000
- Married Filing Separately: $125,000
If your modified adjusted gross income exceeds the threshold, a portion of your gain can be subject to this additional tax.
Step-by-Step Practical Example
Suppose you sold 200 shares at $80 per share. You bought them at $50 per share, paid $25 in buy fees, and paid $20 in sell fees. You also had $300 of reinvested dividends over time.
- Gross proceeds = 200 × $80 = $16,000
- Net sale proceeds = $16,000 – $20 = $15,980
- Initial basis = 200 × $50 = $10,000
- Adjusted basis = $10,000 + $25 + $300 = $10,325
- Capital gain = $15,980 – $10,325 = $5,655
Now determine whether this is short-term or long-term. If short-term, the gain is taxed at ordinary rates. If long-term, you apply the capital gains schedule based on your income and filing status. If you have capital loss carryforwards, they can offset this gain and lower your tax bill.
Losses, Offsets, and Tax-Loss Harvesting Basics
Capital losses can be valuable. Tax rules generally net gains and losses across your portfolio. If losses exceed gains, you may be able to deduct up to $3,000 per year against ordinary income ($1,500 if married filing separately), with excess carried forward to future years.
- Use realized losses strategically to offset realized gains.
- Track carryforwards so you do not miss future tax savings.
- Watch wash sale rules when repurchasing substantially identical securities.
Important: A capital loss does not always create an immediate full cash refund. Its value depends on your current and future taxable income, your gains, and annual deduction limits.
Specific Share Identification vs FIFO
If you bought the same stock at different times and prices, your basis depends on which lots you sell. Many brokers default to FIFO (first in, first out), but specific share identification can be more tax efficient.
- FIFO: First shares purchased are treated as first sold.
- Specific ID: You select high-basis or low-basis lots depending on your tax objective.
Before selling, confirm your lot method in your brokerage settings and keep records of lot selection instructions.
Common Mistakes That Increase Capital Gains Tax
- Ignoring fees and commissions in basis or proceeds.
- Forgetting to include reinvested dividends in basis.
- Selling a few days before crossing into long-term status.
- Not using available capital loss carryforwards.
- Overlooking NIIT for higher incomes.
- Assuming all gains are taxed at one flat percentage.
Planning Tips Before You Sell Stock
- Estimate your year-end taxable income before placing a large sale.
- Check whether waiting can convert a short-term gain into a long-term gain.
- Review unrealized losses in other positions for potential offset opportunities.
- Model federal, state, and NIIT impact together, not separately.
- Coordinate timing of bonus income, RSU vesting, and stock sales.
For high earners and concentrated stock positions, good timing can make a substantial difference in after-tax proceeds without changing your investment thesis.
Authoritative Resources for Verification
Use primary sources to confirm rules for your tax year and circumstances:
- IRS Tax Topic 409: Capital Gains and Losses
- IRS Publication 550: Investment Income and Expenses
- SEC Investor.gov Education Resources
Final Takeaway
To calculate capital gains on a stock sale correctly, focus on five pillars: accurate basis, net proceeds after fees, holding period classification, gain-loss netting, and correct tax rate application including NIIT and state taxes. The calculator above gives you a practical estimate, but your return filing may include additional elements such as wash sales, multiple lots, or special tax circumstances. When in doubt, reconcile your estimate with broker 1099-B data and consult a qualified tax professional.