Selling Index Funds? How Capital Gains Tax Is Calculated

Quick answer: Subtract your cost basis, including reinvested dividends, from the sale amount. Shares held over one year get long-term federal rates of 0%, 15%, or 20% based on income; shares held one year or less are taxed as ordinary income. Sales inside a 401(k) or IRA owe no capital gains tax.↗ Share on X
To calculate capital gains tax on an index fund sale, subtract your cost basis (what you paid, including reinvested dividends) from the sale amount, then apply the right tax rate based on how long you held the shares. Shares held more than one year get long-term rates of 0%, 15%, or 20% at the federal level, depending on your taxable income. Shares held one year or less are taxed as ordinary income, at your regular tax bracket. If you sell inside a 401(k) or IRA, there is no capital gains tax on the sale at all.
Below is the step-by-step math, a worked example, and the mistakes that make people pay more than they owe.
This article is general education, not tax advice. Your situation may have details that change the answer, so check with a tax professional or CPA before a large sale.
What is a capital gain, in plain words?
How to Calculate Dividend Yield on Index Funds, Step by Step →
Invest $100 a Month in Index Funds: A Stress-Free Setup →
What Savings Rate Do You Need for Retirement at Age 30? →A capital gain is the profit you make when you sell something for more than you paid. For an index fund, the "something" is your fund shares.
- Sale price minus cost basis = gain (or loss, if the number is negative).
- Cost basis is your total cost for the shares you sold. It includes the purchase price plus any fees, plus every reinvested dividend or capital gain distribution that bought more shares.
You only owe tax on a gain when you sell (this is called "realizing" the gain). If the fund goes up and you keep holding, there is no capital gains tax on the sale yet.
Clear money tips in your inbox. No hype.
How do I calculate my gain step by step?
Affiliate link. We may earn a commission on purchases, at no extra cost to you.
This content is informational and is not investment advice or financial consulting.
Follow these six steps for each sale.
1. Find the sale amount. Look at your brokerage confirmation or Form 1099-B. Use the net amount after any fees.
2. Find the cost basis of the exact shares sold. Your broker usually reports this on Form 1099-B for shares bought in recent years. For very old shares, you may need your own records.
3. Check which cost basis method was used. This decides *which* shares were sold (more on this below).
4. Split the shares by holding period. Shares held more than one year are long-term. Shares held one year or less are short-term. One sale can include both.
5. Subtract basis from sale amount for each group. You now have a short-term gain or loss and a long-term gain or loss.
6. Net them together. Short-term losses offset short-term gains first, long-term losses offset long-term gains first, then any leftover loss can offset the other type.
What tax rate applies to my gain?
How Much to Save for Retirement: 6-Step Do-It-Yourself Math →
How to Read a Brokerage Statement: The 4 Parts That Matter →
How to Calculate Retirement Savings Before Quitting →| Holding period | Type | Federal rate |
|---|---|---|
| One year or less | Short-term | Your ordinary income tax bracket |
| More than one year | Long-term | 0%, 15%, or 20%, based on taxable income |
The income cutoffs for 0%, 15%, and 20% change every year with inflation and depend on your filing status (single, married filing jointly, and so on). Look up the current year's thresholds on IRS.gov or in your tax software rather than relying on an old chart.
Two extra layers can apply:
- Net Investment Income Tax (NIIT): an extra 3.8% on investment income for people whose modified adjusted gross income is above $200,000 (single) or $250,000 (married filing jointly).
- State income tax: most states tax capital gains as regular income. A few states have no income tax.
Can you show me a worked example?
Here is a simple example with round numbers. These are made-up figures, used only to show the math.
Maria bought index fund shares over time in a regular taxable brokerage account:
| Purchase | Shares | Cost |
|---|---|---|
| Original purchase, 3 years ago | 100 | $10,000 |
| Reinvested dividends over 3 years | 6 | $650 |
| Purchase 8 months ago | 20 | $2,600 |
| Total | 126 | $13,250 |
She sells all 126 shares today for $16,380 total.
- Long-term shares: the 100 original shares plus the reinvested dividend shares that were bought more than a year ago. Say all 6 dividend shares qualify. Basis = $10,650. Sale value of those 106 shares = 106 × $130 = $13,780. Long-term gain = $3,130.
- Short-term shares: the 20 shares bought 8 months ago. Basis = $2,600. Sale value = 20 × $130 = $2,600. Short-term gain = $0.
If Maria is in the 15% long-term bracket, her federal capital gains tax on this sale is about $3,130 × 15% = $469.50, plus any state tax and NIIT if they apply to her.
Notice what happens if she forgets the reinvested dividends: her basis drops from $10,650 to $10,000, and her reported gain grows by $650. At 15%, she would pay about $97.50 extra in tax on money that was already taxed when the dividends were paid.
Why do reinvested dividends matter so much?
Every year your index fund pays dividends. If you reinvest them, you pay tax on those dividends in that year, and they buy more shares. Those new shares have a cost basis equal to the reinvested amount.
If you leave them out of your basis when you sell, you pay tax on the same money twice. Over 10 or 20 years of reinvesting, this can add up to a large number. Most brokers track this for you, but check your 1099-B, especially for shares moved between brokers.
Which cost basis method should I use?
When you sell only part of your shares, the method decides which shares you sold. That changes your gain and your holding period.
| Method | How it works | Good for |
|---|---|---|
| FIFO (first in, first out) | Oldest shares sold first | Simple; often gives long-term treatment, but oldest shares may have the biggest gains |
| Specific identification | You pick the exact lots to sell | Most control; can pick high-basis shares to lower the gain |
| Average cost | Basis is the average price of all shares | Allowed for mutual fund shares; easy, but less control |
Most brokers let you set a default method in your account settings. Choose the method before you place the sale. Changing it after the trade settles is usually not possible.
A common strategy is to sell the lots with the highest cost basis that have also been held more than one year. That keeps the gain small and the rate low.
What if I sold at a loss?
A loss can lower your taxes.
- Losses first cancel out gains of the same type, then the other type.
- If losses are bigger than all your gains, you can deduct up to $3,000 a year against ordinary income ($1,500 if married filing separately).
- Anything left over carries forward to future years.
Watch out for the wash sale rule. If you buy the same or a "substantially identical" fund within 30 days before or after selling at a loss, you can't claim the loss right away. It gets added to the basis of the new shares instead. Automatic dividend reinvestment can trigger this by accident, so consider pausing it before selling at a loss. Whether two different index funds that track the same index count as substantially identical is not fully settled, so ask a tax professional before relying on a swap.
What about capital gain distributions I didn't sell?
Index mutual funds sometimes pay capital gain distributions at year-end, even if you never sold a share. These show up on Form 1099-DIV and are taxed as long-term gains no matter how long you held the fund.
Index ETFs tend to pay these less often because of how they are built, but it can still happen. If you hold index funds in a taxable account, check your 1099-DIV every year.
Which tax forms will I see?
- Form 1099-B from your broker: lists each sale, date, proceeds, and usually your cost basis.
- Form 8949: where you list sales, especially if basis was not reported or needs a correction.
- Schedule D: totals your short-term and long-term gains and losses.
- Form 1099-DIV: dividends and capital gain distributions.
Tax software usually imports the 1099-B directly. Still, compare the cost basis it shows against your own records before you file.
What mistakes cost people the most?
- Selling shares a few days before they hit the one-year mark, turning a long-term gain into a short-term one.
- Leaving reinvested dividends out of cost basis.
- Triggering a wash sale through automatic reinvestment.
- Selling in a taxable account when you could have rebalanced inside an IRA or 401(k) instead, where sales are not taxed.
- Not setting a cost basis method before selling.
When should I talk to a professional?
Talk to a CPA or enrolled agent if your sale is large, if you have shares inherited from someone (inherited shares usually get a new basis), if shares were gifted to you, if your broker shows "basis not reported," or if you are close to the NIIT income line. A one-hour consultation can cost far less than a filing mistake.
Your next step
Log in to your brokerage account today, open the "cost basis" or "unrealized gains" page for your index fund, and look at each lot: purchase date, basis, and current gain. Before you sell anything, confirm your cost basis method in account settings and note which lots will pass the one-year mark soon. If the sale is large, bring that page to a tax professional before you click "sell."
FAQ
Do reinvested dividends count in my cost basis?
Yes. Each reinvested dividend bought new shares, and you already paid tax on it that year. Adding it to your cost basis keeps you from paying tax on the same money twice when you sell.
How long must I hold an index fund to get long-term rates?
More than one year from the purchase date of each lot. Shares bought at different times, including reinvested dividend shares, each have their own holding period.
Can I deduct a loss from selling an index fund?
Losses offset capital gains first, then up to $3,000 a year of ordinary income ($1,500 if married filing separately), with the rest carried forward. Buying the same fund within 30 days before or after the sale can trigger the wash sale rule and delay the loss.
Clear money tips in your inbox. No hype.
Educational content, not personalized financial advice. Sources cited where applicable.
