⏱ 12 min read
Selling stock can feel like a win — until you realize the IRS wants a cut of your gains. Whether you’re cashing out a winning tech position, rebalancing a brokerage account, or liquidating shares to fund a home purchase, understanding how capital gains tax works when selling US stocks (with examples) is essential to keeping more of what you’ve earned. The tax code treats gains differently depending on how long you held the stock, your income level, and even the type of account the shares sit in.
Too many investors discover the tax consequences of a sale only after it’s too late to plan around them. This guide breaks down the mechanics of capital gains taxation step by step — short-term versus long-term rates, how cost basis is calculated, the role of tax-loss harvesting, the Net Investment Income Tax, and strategies high earners use to legally minimize what they owe. Each section includes realistic dollar-figure examples so you can see exactly how the math plays out, not just abstract rules. By the end, you’ll know how to plan a stock sale strategically instead of reactively.
1. Short-Term vs. Long-Term Capital Gains: Why Holding Period Is Everything
The single biggest factor determining your tax bill when you sell a stock is how long you held it. The IRS draws a hard line at 366 days (one year and a day).
Short-term capital gains apply to stocks held one year or less. These gains are taxed as ordinary income, stacked on top of your wages and other income, at your marginal tax rate — which can run as high as 37% at the federal level for top earners.
Long-term capital gains apply to stocks held more than one year. These get preferential tax treatment, taxed at 0%, 15%, or 20% depending on your total taxable income.
Example: Sarah’s Two Trades
Sarah, a single filer with $95,000 in wage income, sells two stock positions in the same year:
- Trade A: She bought 100 shares of a growth stock for $10,000 in March and sold them in November (8 months later) for $16,000 — a $6,000 gain. Because she held it less than a year, this is a short-term gain. It’s added to her ordinary income, taxed within the 22% federal bracket. She could owe roughly $1,320 in federal tax on that gain alone, depending on where it falls in her bracket.
- Trade B: She bought 200 shares of a dividend stock for $8,000 fourteen months earlier and sold for $12,000 — a $4,000 gain. Since she held it over a year, this qualifies as long-term. At her income level, she likely falls into the 15% long-term capital gains bracket, owing about $600.
Same investor, similar gain size, but drastically different tax outcomes based purely on timing. This is why financial advisors constantly repeat: if you’re close to the one-year mark and a sale isn’t urgent, waiting even a few extra weeks can meaningfully cut your tax bill. Always check your exact purchase date (trade date, not settlement date) before selling — brokerages like Fidelity and Charles Schwab display holding period and estimated gain/loss directly in your account before you confirm a trade.
2. How Cost Basis Is Calculated (and Why It’s Often Wrong)
Capital gains tax is only ever assessed on your gain — the difference between your sale price and your cost basis (what you originally paid, adjusted for reinvested dividends, stock splits, and fees). Getting cost basis right is critical because errors here directly inflate or deflate your taxable gain.
What counts toward cost basis:
- Original purchase price of the shares
- Commissions or transaction fees paid to acquire them
- Reinvested dividends (each dividend reinvestment purchase creates a new tax lot with its own basis and holding period)
- Adjustments for stock splits (a 2-for-1 split halves your per-share basis but doubles your share count)
Example: Dividend Reinvestment Complications
Marcus bought 50 shares of an S&P 500 index fund for $5,000 in 2019. Over six years, he reinvested $600 in dividends, buying small additional share lots each quarter. When he sells his entire position in 2026 for $9,200, his taxable gain is not $4,200 (sale price minus original purchase only) — it’s $9,200 minus his total basis of $5,600 (original investment plus reinvested dividends), which equals $3,600. If he forgot to include the reinvested dividends in his basis, he’d overpay tax on $600 he already paid tax on the year those dividends were received.
Actionable steps to get cost basis right:
- Check your 1099-B. Brokerages are required to report cost basis for “covered securities” (generally shares bought after 2011) directly to the IRS. Log into your brokerage’s tax center and download the 1099-B before filing.
- Watch for “noncovered” shares. Older holdings, shares transferred between brokers, or employer stock plans sometimes have basis reported incorrectly or not at all. You may need old trade confirmations to verify.
- Choose your cost basis method deliberately. If you own multiple lots of the same stock bought at different times and prices, you can often choose which lots to sell using methods like FIFO (first-in-first-out), specific identification, or average cost. Specific identification lets you cherry-pick high-basis (low-gain) lots to minimize tax owed on a partial sale.
- Use your broker’s basis lookup tool before placing a sell order — most major platforms let you see the gain/loss lot-by-lot in real time.
3. Capital Gains Tax Brackets and How Income Stacks
Long-term capital gains rates aren’t a flat percentage — they’re bracket-based, just like ordinary income tax, and they “stack” on top of your other taxable income. The IRS adjusts these bracket thresholds annually for inflation, so always confirm the current-year cutoffs on IRS.gov before finalizing a sale near a bracket edge.
Here’s the conceptual structure: there are three long-term capital gains rates — 0%, 15%, and 20% — and which one applies depends on your total taxable income (wages plus gains plus everything else) relative to the annual thresholds. Importantly, your ordinary income “fills up” the lower brackets first, and your capital gains are taxed based on where they land on top of that ordinary income — not based on your gain amount in isolation.
Example: The Bracket-Stacking Effect
Consider a married couple, Dan and Priya, filing jointly with $70,000 in combined wage income for 2026. They sell long-held stock for a $40,000 long-term gain.
- Their $70,000 in wages fills the lower part of the income scale.
- Their $40,000 capital gain then stacks on top. For 2026, after the $32,200 MFJ standard deduction their taxable income is $37,800; stacking the $40,000 gain brings them to $77,800 — still below the $98,900 threshold where the 0% long-term capital gains rate ends for joint filers. Result: their entire $40,000 gain is taxed at 0%. With higher wages or a bigger gain, the portion crossing that threshold would be taxed at 15%.
This is a crucial planning insight: retirees or lower-income years (e.g., a sabbatical, early retirement before Social Security starts, or a year with a big deductible loss) can be ideal windows to realize long-term gains at the 0% rate. A financial advisor or a tool like TurboTax’s capital gains calculator can model this stacking effect using your actual numbers before you sell.
Actionable tip: If you’re near a bracket threshold, consider splitting a large sale across two tax years (selling half in December, half in January) to keep more of the gain in a lower bracket each year.
4. The Net Investment Income Tax (NIIT) and High-Income Surprises
Beyond ordinary capital gains rates, high earners face an additional 3.8% Net Investment Income Tax (NIIT) on investment income — including capital gains — once modified adjusted gross income (MAGI) exceeds certain thresholds (currently $200,000 for single filers and $250,000 for married filing jointly; these thresholds are not inflation-indexed and have stayed fixed for years).
Example: The NIIT Surprise
Elena, a single software engineer, earns $185,000 in salary. She sells restricted stock units (RSUs) that have vested and appreciated, realizing a $60,000 long-term capital gain. Her total MAGI becomes $245,000 — $45,000 over the $200,000 NIIT threshold.
The NIIT applies to the lesser of her net investment income ($60,000) or the amount her MAGI exceeds the threshold ($45,000). Since $45,000 is smaller, she owes 3.8% tax on $45,000 — an additional $1,710 — on top of her regular 15% or 20% long-term capital gains tax.
Elena didn’t budget for this because she was focused only on the “15% long-term rate” headline number. In reality, her effective rate on this sale was closer to 18.8%–23.8% once NIIT is layered in.
Actionable steps for high earners:
- Calculate your MAGI before selling, including the expected gain, to see if you’ll cross the NIIT threshold.
- Consider spreading large sales across multiple years to stay under the threshold in any single year.
- Offset gains with tax-loss harvesting (see Section 5) to reduce net investment income subject to NIIT.
- Consult the IRS Instructions for Form 8960 to see exactly how NIIT is calculated on your specific income mix.
5. Tax-Loss Harvesting: Using Losses to Offset Gains
The tax code allows you to use capital losses to directly offset capital gains, and this is one of the most underused strategies among everyday investors. If your losing positions are sold in the same year as your winners, the losses reduce your taxable gain dollar-for-dollar.
How it works, step by step:
- Net your gains and losses by category. Short-term gains offset short-term losses first; long-term offsets long-term first. Then any excess nets across categories.
- If losses exceed gains, you can deduct up to $3,000 of the excess against ordinary income per year ($1,500 if married filing separately).
- Unused losses carry forward indefinitely to future tax years — they don’t expire.
Example: Offsetting a Big Winner
James sells a concentrated stock position for a $25,000 long-term gain. Earlier in the year, he also sold a losing position in a different holding for a $9,000 long-term loss. Netting these, his taxable long-term gain drops to $16,000 — cutting his tax bill by roughly $1,350–$1,800 depending on his bracket, simply by realizing a loss he was already sitting on.
The wash-sale rule trap: If James had sold that losing stock and repurchased the same or a “substantially identical” security within 30 days before or after the sale, the IRS disallows the loss under the wash-sale rule. This applies across all his accounts, including IRAs. To stay compliant while maintaining market exposure, investors often swap into a similar-but-not-identical ETF for the 31-day window before buying back the original holding.
Many robo-advisors and brokerage platforms, including Fidelity and Betterment, offer automated tax-loss harvesting features that scan portfolios daily for harvesting opportunities while avoiding wash-sale violations.
6. Selling Employer Stock, RSUs, and ISOs: Special Rules to Know
Employer-granted stock introduces extra layers of complexity because part of the value was already taxed as compensation before you ever “sold” anything.
RSUs (Restricted Stock Units): When RSUs vest, their full value is taxed as ordinary income (with taxes typically withheld automatically). Your cost basis becomes the value at vesting. When you later sell, you only owe capital gains tax on appreciation since vesting — not the full sale price.
Example: Priya’s RSUs vest at $50/share (2,000 shares = $100,000, taxed as ordinary income immediately, with the $100,000 becoming her cost basis). She sells 18 months later at $70/share ($140,000 total). Her taxable capital gain is only $40,000 (the appreciation since vesting), taxed at long-term rates since she held over a year post-vest — not $140,000.
ISOs (Incentive Stock Options): These carry more risk because exercising can trigger the Alternative Minimum Tax (AMT), even before you sell. To get favorable long-term capital gains treatment on the full spread, you generally must hold shares at least two years from grant and one year from exercise (a “qualifying disposition”). Selling earlier (“disqualifying disposition”) converts part of the gain to ordinary income.
Actionable steps:
- Track vesting dates and exercise dates separately — they create different holding-period clocks.
- Model AMT exposure before exercising ISOs, ideally with a tax professional, since a large paper gain can trigger real cash tax owed.
- Avoid over-concentration — many advisors recommend diversifying employer stock down to a small percentage of net worth once vested and taxed, to reduce single-stock risk alongside tax exposure.
Key Takeaways
- Holding a stock more than one year shifts your gain from ordinary income tax rates to preferential long-term capital gains rates — timing a sale matters enormously.
- Cost basis must include reinvested dividends and adjustments for splits; always verify your broker’s 1099-B rather than assuming it’s correct.
- Long-term capital gains rates stack on top of your ordinary income, meaning your bracket depends on total taxable income, not the gain alone.
- High earners should watch for the 3.8% Net Investment Income Tax once MAGI exceeds $200,000 (single) or $250,000 (married filing jointly).
- Tax-loss harvesting can offset gains dollar-for-dollar and up to $3,000 against ordinary income annually, with unused losses carrying forward indefinitely.
- Watch the wash-sale rule — repurchasing a substantially identical security within 30 days disallows the loss deduction.
- RSUs and ISOs have unique basis and holding-period rules tied to vesting and exercise dates, not just the original grant date.
Conclusion
Understanding how capital gains tax works when selling US stocks (with examples) turns tax season from a source of surprise into a tool for proactive planning. From holding periods and cost basis accuracy to NIIT thresholds and tax-loss harvesting, every lever in this guide can meaningfully change your after-tax return. The difference between a rushed sale and a strategically timed one can easily be thousands of dollars. Before your next trade, run the numbers, check your brokerage’s basis and gain/loss tools, and consider consulting a CPA, an Enrolled Agent (EA), or a CFP if your position is large or complex. Smart selling isn’t just about market timing — it’s about tax timing too.
Disclaimer: The content on this site is for general informational purposes only and is not financial, tax, or investment advice. Verify current IRS rules and consult a licensed professional before making decisions.
