When you sell a stock for more than you paid, the profit is a capital gain — and the IRS wants a cut. As a tax professional who spends every filing season untangling brokerage 1099-Bs for investors, I can tell you that most people overpay simply because they don't understand which rate applies, how to track their cost basis, or how to use losses to offset gains. This guide walks through exactly how to calculate capital gains tax on stocks, with worked examples for 2026 sales.
If you want to model your own sale before reading further, our Capital Gains Tax Calculator runs the math for you.
Capital Gains Basics
A capital gain (or loss) is triggered only when you sell the security. Unrealized gains — paper gains while you still hold the shares — are not taxed. The core formula:
Capital Gain = Sale Price − Cost Basis − Selling Costs
Where cost basis is what you paid to acquire the shares:
- Purchase price of the shares
- Brokerage commissions on the purchase
- Reinvested dividends (these get added to basis, so they aren't taxed again as gains)
Selling costs — typically your brokerage commission on the sale — reduce the proceeds before the gain is computed. The IRS lays out the full framework in IRS Publication 550, Investment Income and Expenses, and the mechanics of reporting each trade are documented in IRS Form 8949, Sales and Other Dispositions of Capital Assets.
Short-Term vs Long-Term Capital Gains
The single most important factor in your tax bill is the holding period. Under Internal Revenue Code Section 1222, gains are classified as short-term or long-term based on how long you held the shares before selling:
| Type | Holding Period | Tax Rate |
|---|---|---|
| Short-term | 1 year or less | Ordinary income rates (10%–37%) |
| Long-term | More than 1 year | Preferential rates (0%, 15%, 20%) |
The clock starts the day after you acquire the shares and ends on the day you sell. Buy on January 2, sell on January 2 of the following year, and you have a long-term gain.
2026 Long-Term Capital Gains Brackets
For tax year 2026, long-term capital gains are taxed at 0%, 15%, or 20% based on your taxable income (which includes the gain itself):
| Rate | Single | Married Filing Jointly |
|---|---|---|
| 0% | Up to $48,000 | Up to $96,000 |
| 15% | $48,001 – $533,400 | $96,001 – $640,000 |
| 20% | Above $533,400 | Above $640,000 |
Net Investment Income Tax (NIIT)
High earners face an additional layer. The 3.8% Net Investment Income Tax applies to the lesser of your net investment income or the amount by which your modified adjusted gross income (MAGI) exceeds:
- $200,000 (single)
- $250,000 (married filing jointly)
So a top-bracket investor can effectively pay 23.8% on long-term gains. Compare your situation side by side with the Short vs Long-Term Capital Gains Calculator to see how the holding period changes the math.
Worked Examples
Example 1: Long-Term Gain, Moderate Income
You bought 100 shares at $50, paying a $10 commission. Your cost basis is $5,010. Eighteen months later you sell all 100 shares at $80, less a $10 commission. Your net proceeds are $7,990.
- Gain: ($8,000 − $10) − ($5,000 + $10) = $2,980
- Holding period: 18 months → long-term
- Filing status: Single, taxable income $75,000 → 15% bracket
- Tax: $2,980 × 0.15 = $447
Example 2: Short-Term Gain, High Income
Same trade, but you held the shares only 6 months. The $2,980 gain is now short-term and taxed at your ordinary marginal rate. Assuming a 24% bracket:
- Tax: $2,980 × 0.24 = $715
Holding 6 months instead of 18 cost you an extra $268 in tax on the identical trade. That is the entire case for patient investing.
Example 3: Long-Term Gain in the 0% Bracket
A retired couple has taxable income of $60,000 from Social Security and a small pension. They realize a $20,000 long-term gain. Their total taxable income of $80,000 stays under the $96,000 MFJ threshold for the 0% rate.
- Tax: $0
This is one of the most powerful planning moves in the tax code: retirees in the 0% bracket can harvest gains tax-free. Just be cautious — large gains can push you into the 15% bracket or trigger NIIT.
Cost Basis Tracking Methods
When you buy the same stock at different prices over time (as happens with a dividend reinvestment plan you can model with our Dividend Calculator), you need a method to determine which shares you sold:
- First-in, first-out (FIFO): The default if you don't specify. The oldest shares are deemed sold first — often the ones with the smallest gain, but not always.
- Specific share identification: You tell your broker exactly which lots to sell. This gives you the most control and is the method I recommend to clients who actively manage taxes.
- Average cost: Available only for mutual funds, not individual stocks. The IRS lets you average the basis across all shares.
Whatever method you choose, track reinvested dividends. Each reinvestment is a separate purchase that adds to your basis. Miss them and you will overpay tax on every sale. Brokers are now required to report cost basis on Form 1099-B for covered shares, but you remain responsible for non-covered holdings.
Tax-Loss Harvesting
Losses are not all bad news — they can offset gains dollar for dollar. The rules under IRS Publication 544, Sales and Other Dispositions of Assets:
- Offset gains: Capital losses first offset capital gains of the same type (short-term losses against short-term gains, long-term against long-term), then the other type.
- Offset ordinary income: If net losses exceed net gains, you can deduct up to $3,000 of the excess against ordinary income each year ($1,500 if married filing separately).
- Carry forward: Unused losses carry forward indefinitely to future years until consumed.
- Wash sale rule: You cannot claim a loss if you buy the same or a "substantially identical" security within 30 days before or after the sale. The IRS disallows the loss and adds it to the new shares' basis.
Special Situations
A few scenarios change the standard calculation:
- Qualified small business stock (Section 1202): Gains on eligible QSBS held more than 5 years can be excluded up to the greater of $10 million or 10× your basis per issuer.
- Primary residence (Section 121): Excludes up to $250,000 (single) or $500,000 (MFJ) of gain if you owned and used the home as your primary residence for 2 of the last 5 years.
- Inherited stock: Receives a stepped-up basis to fair market value on the date of death. Beneficiaries typically owe no capital gains tax on appreciation that occurred during the decedent's life.
- Gifted stock: Carries over the donor's basis. If you sell gifted stock at a gain, your basis is what the donor paid; if you sell at a loss, the basis is the lesser of the donor's basis or fair market value at the gift date.
State Capital Gains Tax
Federal tax is only part of the bill. Most states tax capital gains as ordinary income:
- California: 1%–13.3%, with no preferential rate for long-term gains.
- Texas, Florida, Tennessee: 0% state income tax.
- Montana, North Dakota: Lower capital gains rates or credits than ordinary income.
If you live in a high-tax state, your effective rate on a long-term gain can exceed 30% when federal, NIIT, and state taxes combine. Use the Income Tax Calculator to estimate your total federal + state burden, and the Investment Calculator to project after-tax growth over time. Long-term holders can also use the Compound Interest Calculator to see how deferring sales compounds wealth.
Bottom Line
Calculating capital gains tax on stocks comes down to four steps: find your cost basis (purchase price + commissions + reinvested dividends), determine your holding period (over 1 year = long-term), apply the correct 2026 rate (0%, 15%, or 20%, plus 3.8% NIIT if applicable), and report the sale on Form 8949 and Schedule D. Track your lots, harvest losses to offset gains, and watch the wash sale rule. Done right, the difference between short-term and long-term treatment — and between ignoring losses and harvesting them — can mean thousands of dollars saved each year.
Next Steps
- Run the numbers on your planned sale with the Capital Gains Tax Calculator.
- Compare holding periods side by side with the Short vs Long-Term Capital Gains Calculator.
- Estimate your total tax burden — federal and state — with the Income Tax Calculator.
- Project after-tax portfolio growth with the Investment Calculator and the Compound Interest Calculator.
- Model dividend reinvestment and basis with the Dividend Calculator.
Sources
- IRS Publication 550, Investment Income and Expenses — defines cost basis, holding periods, and investment income reporting.
- IRS Form 8949, Sales and Other Dispositions of Capital Assets — the form used to report each stock sale.
- IRS Form Schedule D, Capital Gains and Losses — summarizes Form 8949 and computes the tax.
- IRS Publication 544, Sales and Other Dispositions of Assets — covers gains, losses, wash sales, and special property transactions.
- Internal Revenue Code Section 1222 — statutory definition of short-term and long-term capital gains.
Related articles
$50,000 a Year Is How Much Per Hour? (2026 Breakdown)
$50,000/year equals $24.04/hour based on a 2,080-hour work year. See the real take-home hourly rate after taxes, benefits, and PTO.
$25/Hour Is How Much a Year? (Before & After Taxes)
$25/hour translates to $52,000/year gross. See the take-home pay in every state, plus how overtime, PTO, and 401(k) contributions change the math.
Part-Time to Full-Time Salary Equivalent Calculator (2026)
Convert part-time hourly pay to full-time equivalent salary. Learn the FTE formula, pro-rata benefits math, and how to compare part-time and full-time offers fairly.
Salary Needed to Live Comfortably in NYC (2026)
A comfortable life in New York City in 2026 requires $110,000–$150,000 for a single person and $180,000+ for a family. See the full budget breakdown by borough.
How to Calculate Tip Percentage on a Bill
Tip etiquette by service, country, and party size. Plus mental math tricks, tax-and-tip calculations, and how to split a bill across friends.
How to Calculate Overtime Pay at Time-and-a-Half
FLSA overtime rules explained: who qualifies, how to calculate time-and-a-half and double-time, and common employer mistakes to watch for.