Swap Stocks for Index Funds and Keep Your Tax Bill Small

Quick answer: Switch freely inside IRAs and 401(k)s, where selling is not taxed. In a taxable account, send new money and dividends to index funds, sell losing stocks first to offset gains, pick high-cost lots held over a year, and sell big winners slowly across years. Talk to a CPA if the amounts are large.↗ Share on X
You can move from individual stocks to index funds with little or no capital gains tax if you do it in the right order: switch freely inside retirement accounts (no tax there), send all new money and dividends to index funds, sell your losing stocks first to create tax losses, and sell winners slowly, ideally after you have held them more than a year. In a regular taxable brokerage account, there is no way to sell a stock at a profit and owe nothing in every case. But with a plan, most people can shrink the bill a lot or spread it over several years.
This article walks through each method, in the order most people should try them, with simple examples. Tax rules depend on your income and your state, so treat this as a map, not as personal tax advice. If the amounts are large, talk to a CPA or tax professional before you sell.
First question: what kind of account are your stocks in?
6 Ways to Rebalance Your Portfolio and Avoid Capital Gains →
Retirement Savings Rate From Gross Pay: The 6-Step Formula →
Rebalance Your Portfolio Without Owing Taxes: 6 Smart Moves →This one answer changes everything.
| Account type | Do you owe tax when you sell? | What to do |
|---|---|---|
| 401(k), 403(b), traditional IRA | No, not when you sell inside the account | Sell stocks and buy index funds today. No capital gains tax. |
| Roth IRA | No | Same: switch freely. |
| HSA (invested) | No | Same: switch freely. |
| Regular (taxable) brokerage account | Yes, on any profit | Use the step-by-step plan below. |
Inside retirement accounts, buying and selling does not create a tax bill. Tax only matters when money comes out (and for Roth, often not even then). So if your stocks are in an IRA or 401(k), you can stop reading the tax sections and simply make the switch.
Most of the work is for the taxable account, where every sale at a profit is a taxable event.
Clear money tips in your inbox. No hype.
How does capital gains tax work, in plain words?
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.
When you sell a stock for more than you paid, the profit is a capital gain. What you paid, including the cost of reinvested dividends, is called your cost basis.
Example: you bought 50 shares at $40 ($2,000 total). Today they are worth $70 ($3,500 total). Your gain is $1,500. You only pay tax on the $1,500, not on the full $3,500.
How long you held the stock matters a lot:
- Held one year or less: short-term gain, taxed like your regular paycheck income.
- Held more than one year: long-term gain, taxed at lower rates. For people with lower taxable income, the long-term rate can be 0%.
The income limits for each rate change every year, so check the current IRS numbers or ask a tax preparer before you decide.
Step 1: Stop adding to individual stocks
Savings to Brokerage: Does Moving Money Cost You Taxes? →
Your First Index Fund: 6 Checks Before You Click Buy →
13 Retirement Savings Tips That Work on a Normal Paycheck →This is the easiest move and it costs nothing.
1. Turn off automatic dividend reinvestment on your individual stocks. Have dividends paid as cash instead.
2. Use that cash, plus any new money you save, to buy a broad index fund (for example, a total US stock market fund or an S&P 500 fund).
3. Repeat every month.
No stock is sold, so no gain is realized. Over time, the index fund becomes a bigger share of your portfolio on its own. Note: the dividends themselves are still taxable in the year you receive them, whether reinvested or not. This step does not change that.
Step 2: Sell your losers first
Look at each stock in your taxable account. Some are probably worth less than you paid. Selling those creates a capital loss, and losses are useful:
- Losses cancel out gains in the same year, dollar for dollar.
- If losses are bigger than gains, you can use up to $3,000 of extra loss per year to lower your regular income.
- Any loss left over carries forward to future years.
Example:
| Stock | Paid | Worth now | Result if sold |
|---|---|---|---|
| Stock A | $5,000 | $3,000 | $2,000 loss |
| Stock B | $2,000 | $4,000 | $2,000 gain |
| Net | $0 taxable gain |
Sell both in the same year, buy the index fund with the $7,000, and you have moved $7,000 into the index fund with no net gain to report.
Watch the wash sale rule. If you sell a stock at a loss and buy the same stock (or something "substantially identical") within 30 days before or after, the IRS does not let you use the loss right away. Buying a broad index fund after selling one company's stock is generally not treated as identical. But do not buy back the same company's shares within that window, and check that automatic reinvestment is off.
Step 3: Pick which shares to sell
If you bought the same stock at different times and prices, you probably own several tax lots (groups of shares with different cost basis). Many brokers sell the oldest shares first by default, which are often the ones with the biggest gain.
Instead:
1. Log in to your broker and find the cost basis or "lots" page for that stock.
2. Change the sale method to specific identification (sometimes called "specific lot" or "highest cost").
3. Choose to sell the shares with the highest cost basis first. That means the smallest gain, or even a loss.
4. Prefer lots held more than one year, so any gain is long-term.
This small setting can change the tax on the same sale by a large amount.
Step 4: Sell winners slowly, and time it
For stocks with big gains, you do not have to sell everything at once. Spreading sales over several tax years can keep you in a lower bracket each year.
A simple plan:
1. Make a list of your winning stocks, with the gain on each.
2. Wait until any lot you plan to sell has been held more than one year.
3. Decide on a yearly amount of gain you are comfortable paying tax on.
4. Sell that amount each year, usually in a year when your income is lower (a gap between jobs, a sabbatical, the first years of retirement).
5. Put the cash straight into your index fund.
If your taxable income is low enough in a given year, part or all of your long-term gains may fall in the 0% bracket. Run the numbers with tax software or a preparer before the sale, not after.
Step 5: Give shares instead of cash
If you already give money to charity or help family, this can be a smart way to get rid of a stock with a big gain:
- Charity: donate the appreciated shares directly to a qualified charity or a donor-advised fund, held more than one year. In general you do not pay capital gains tax on that gain, and you may get a deduction if you itemize. Then use the cash you would have donated to buy your index fund.
- Family: you can gift shares to a family member. They take over your cost basis. If their income is low, their tax rate on the gain may be lower than yours. Be careful: rules for children (the "kiddie tax") and gift limits apply. Get advice first.
Step 6: Some shares may be best left alone
For a stock with a very large gain, especially if you are older, it can make sense to hold it and not sell. Under current US tax law, heirs usually receive inherited stock with a "stepped-up" basis, meaning the gain built up during your lifetime is generally not taxed. Laws can change, so review this with an estate or tax professional.
If you keep a few individual stocks for this reason, that is fine. The goal is a portfolio that is mostly diversified, not a perfect one.
Putting it all together: a sample order of moves
| Order | Action | Tax cost |
|---|---|---|
| 1 | Switch everything inside IRA / 401(k) / Roth to index funds | None |
| 2 | Redirect dividends and new savings to the index fund | None (dividends still taxed as usual) |
| 3 | Sell losing stocks, pair them with some winners | Low or zero net gain |
| 4 | Sell high-basis, long-term lots first | Small gain |
| 5 | Sell big winners slowly over several years | Spread out, often lower rate |
| 6 | Donate or gift highly appreciated shares | Often none for you |
| 7 | Consider holding a few huge winners | None while held |
Mistakes to avoid
1. Selling everything in December in one go. One big year of gains can push you into a higher bracket.
2. Selling shares held 11 months. Waiting a few more weeks can turn a short-term gain into a long-term one.
3. Forgetting state tax. Many states also tax capital gains.
4. Triggering a wash sale by buying back the same stock within 30 days.
5. Letting taxes drive everything. If one stock is a huge part of your savings, the risk of keeping it can be bigger than the tax of selling it. A professional can help you weigh both.
Your next step
Today, log in to your brokerage account and write down three things for each individual stock: which account it is in, your cost basis, and the purchase date. Switch everything in retirement accounts to an index fund right away. Then turn off dividend reinvestment on the stocks in your taxable account, and set up an automatic monthly purchase of your chosen index fund. If your total gains are large, take that list to a CPA before selling anything else.
FAQ
Do I pay capital gains tax when I sell stocks in my IRA or 401(k)?
No. Buying and selling inside a retirement account does not create a capital gains tax bill. Tax rules apply when money is withdrawn.
Does buying an index fund after selling a stock at a loss trigger a wash sale?
A broad index fund is generally not considered substantially identical to one company's stock. A wash sale happens if you buy the same stock back within 30 days before or after the sale.
Can I avoid capital gains completely in a taxable account?
Not in every case. You can reduce or spread out the tax by pairing losses with gains, choosing high-cost lots, waiting for long-term status, giving shares to charity, or holding some shares. A tax professional can help with large gains.
Clear money tips in your inbox. No hype.
Educational content, not personalized financial advice. Sources cited where applicable.
