How to Calculate Capital Gains Tax on Stock Sales
For informational purposes only, not financial advice. Full disclaimer
Calculating capital gains tax on a stock sale comes down to four moving parts: what you paid, what you sold it for, how long you held it, and how that gain stacks on top of the rest of your income. The tax formula itself is simple, but cost-basis rules, lot selection, and wash-sale traps make the real-world calculation less obvious than many investors expect.
The IRS reports most stock sales on Form 1099-B, and taxpayers generally reconcile the sale on Form 8949 and Schedule D. IRS Topic No. 409 explains the broad rules for capital gains and losses.
Enter purchase price, sale price, holding period, income, and filing status to estimate the federal tax on your gain.
Try the Capital Gains Tax CalculatorThe Core Formula
Capital gain or loss = Net sale proceeds - Adjusted cost basis- Start with your adjusted cost basis for the shares sold.
- Subtract commissions or selling costs from the gross proceeds to get net sale proceeds.
- Subtract cost basis from net proceeds to find the gain or loss.
- Check the holding period: one year or less is short-term, more than one year is long-term.
- Apply ordinary-income treatment for short-term gains or long-term capital gains treatment for long-term gains.
Step 1: Confirm Your Cost Basis
For a single-lot stock purchase, cost basis is usually just the purchase price plus any purchase commission. But many investors buy shares over time through recurring contributions, dividend reinvestment, or multiple entry points. In those cases, lot selection matters.
If you do nothing, a brokerage may default to FIFO, which usually sells the oldest shares first. Specific identification lets you choose which lot to sell. That can reduce the gain, control whether the sale is long-term or short-term, and lower the tax bill.
Example Calculation
You bought 100 shares at $40, another 100 shares at $58, and then sold 100 shares at $72.
- If FIFO applies, the sold lot may be the $40 shares, creating a $32 per-share gain.
- If you specifically identify the $58 shares, the gain drops to $14 per share.
- On 100 shares, FIFO creates a $3,200 gain while specific identification creates a $1,400 gain.
Lot selection can change the taxable gain dramatically even when the sale price is the same.
Step 2: Check the Holding Period
A stock held for one year or less creates a short-term capital gain, which is generally taxed like ordinary income. A stock held for more than one year creates a long-term gain, which generally falls into the 0%, 15%, or 20% federal long-term capital gains structure under current law.
For planning, that one-day difference can matter a lot. Investors who are close to the one-year mark often compare the tax cost of selling today with the after-tax outcome of waiting until the position qualifies for long-term treatment.
Step 3: Estimate the Tax Layer
Example Calculation
You sell stock for a $12,000 gain after holding it for 18 months. Your other taxable income already places you in the 15% long-term capital gains bucket.
- Long-term gain: $12,000
- Applicable long-term rate in this example: 15%
- Federal capital gains tax estimate: $12,000 x 15% = $1,800
The estimated federal tax is $1,800 before considering any offsetting capital losses or the possible 3.8% NIIT layer for high-income taxpayers.
High-income investors may owe an extra 3.8% Net Investment Income Tax on some or all of a stock gain when total income crosses the IRS threshold.
Read the NIIT GuideCapital Losses and the Wash-Sale Trap
Losses on stock sales can offset capital gains, and net losses can reduce ordinary income up to the annual IRS limit. But the wash-sale rule can disallow the loss if you buy the same or a substantially identical security within the 30-day window before or after the sale.
That rule matters most when investors sell a losing position for tax reasons and immediately buy it back. The loss is not gone forever, but it usually gets rolled into the basis of the replacement shares instead of helping on the current return.
If you are realizing a stock loss for tax purposes, make sure you understand the 30-day wash-sale window before buying back the same position.
What You Need at Tax Time
- Your broker Form 1099-B
- Trade confirmations or lot history if basis is incomplete
- Any records of reinvested dividends that increased basis
- Form 8949 and Schedule D support for gains and losses
The cleanest process is to track the sale at the lot level when you execute it, not months later during tax prep. Knowing the basis method and holding period before you click sell often matters more than trying to optimize after the fact.
Frequently Asked Questions
How do I calculate capital gains tax on stocks?+
What cost basis should I use when I bought shares at different prices?+
Do I owe tax if I reinvest the stock sale proceeds right away?+
What is the wash-sale rule for stocks?+
Can stock losses offset stock gains?+
Related Calculators
Related Guides
Continue through the same topic cluster with connected examples and formulas.
What Is NIIT? Net Investment Income Tax Explained
NIIT is a 3.8% surtax that can apply to capital gains, dividends, interest, rental income, and other investment income when MAGI rises above the IRS threshold.
What Is Capital Gains Tax? Short-Term vs Long-Term Rates 2025
Capital gains tax is a federal tax on the profit you earn when you sell an asset for more than you paid. The rate depends on how long you held the asset and your taxable income.
Marginal vs Effective Tax Rate: What's the Difference?
Your marginal tax rate is the rate on the next dollar you earn. Your effective tax rate is the average rate across all your income. Confusing the two leads to bad salary, bonus, and retirement decisions.
Disclaimer: This article is for informational purposes only and does not constitute financial advice. Consult a qualified financial advisor for decisions about your specific situation.