LearnTaxes
Lesson 5.4 · Taxes

Capital gains and how to harvest them

15 min readLast reviewed November 2026

When you sell an investment outside a retirement account, the tax depends on three things: what you paid for the shares you sold, how long you held them, and what other income the gain lands on top of. You choose all three more often than you'd think. This lesson covers the mechanics, then the two ways of timing a sale that planners call harvesting, and what each one costs.

Cost basis and lots

A capital gain is the sale price minus your cost basis: what you paid, including any commission, plus every dividend you reinvested along the way. The taxable account covers the basics of how a brokerage account is taxed. Here we go one level down, to the shares themselves.

Each purchase is a separate lot with its own price and date, and a reinvested dividend is a small lot of its own. When you sell part of a holding, the gain depends on which lots you sold. There are three ways to decide:

  • First in, first out (FIFO): the oldest shares go first. This is what the IRS assumes if you don't identify the shares, and it's most brokerages' default for stocks and exchange-traded funds.
  • Specific identification: you tell the brokerage which lots to sell, at the time of the sale. Most brokerages let you pick lots on the order screen or set a standing rule such as highest cost first.
  • Average cost: every share gets the same basis, the average of all of them. It's allowed only for mutual fund shares and shares bought through a dividend reinvestment plan, and it's often the default for mutual funds.

Say Sam bought 100 shares of the same mutual fund three times and sells 100 shares in November 2026 at $100 each.

MethodShares soldBasisGain or lossKind
First in, first outThe 2019 lot, bought at $50$5,000$5,000Long-term
Specific identificationThe 2022 lot, bought at $90$9,000$1,000Long-term
Specific identificationThe 2026 lot, bought at $110$11,000−$1,000Short-term
Average costAny 100, at $83.33 each$8,333$1,667Long-term
One sale of 100 shares for $10,000, four possible results. Sam holds 300 shares bought at $50, $90 and $110. The total gain across all 300 shares is the same whichever method is used; the method decides how much of it is taxed now.

Over the life of the holding the total gain comes out the same under every method. What changes is the year it's reported in, and that is worth a good deal. Picking lots lets you raise cash while realizing little gain, realize a loss on purpose, or realize a large gain in a year when it's taxed at 0%.

Brokerages have had to track basis and report it to the IRS on Form 1099-B for stock bought since 2011 and for mutual funds, ETFs and reinvestment-plan shares bought since 2012. For anything older, the records are yours to keep. If you can't show what you paid, the IRS can treat the whole sale price as gain.

Short-term and long-term

Hold an investment for more than one year and the gain is long-term, taxed at the lower rates below. Hold it one year or less and it's short-term, taxed as ordinary income at your bracket rate. The count starts the day after you buy and includes the day you sell, so shares bought on March 10 become long-term if sold on March 11 of the next year or later.

Losses are sorted the same way, and the tax return nets them in order. Short-term losses come off short-term gains, and long-term losses off long-term gains. If one side ends up a net loss and the other a net gain, they're netted against each other. This ordering has a practical consequence. A short-term loss is the most useful kind, because it first cancels short-term gains that would have been taxed at your full bracket rate.

The 2026 rates, and how gains stack

Long-term gains are taxed at 0%, 15% or 20%. Which rate applies depends on your taxable income, the figure left after deductions (see Brackets: marginal and effective), with the gain included.

RateSingleHead of householdMarried filing jointly
0%Up to $49,450Up to $66,200Up to $98,900
15%$49,450–$545,500$66,200–$579,600$98,900–$613,700
20%Over $545,500Over $579,600Over $613,700
2026 federal rates on long-term capital gains and qualified dividends, by taxable income including the gain.

The gain doesn't get its own trip through that table. Your ordinary income (wages, pensions, IRA withdrawals, interest) fills the bottom of the stack, and the gain sits on top of it. Only the part of the gain that pokes above a line pays the higher rate.

Take Sam and Jordan, married and both 60, with $100,000 of pension and IRA income and a $50,000 long-term gain from selling a fund. Their standard deduction is $32,200, so ordinary income takes up $67,800 of taxable income. The gain sits on top of that, from $67,800 to $117,800. The first $31,100 of it reaches the $98,900 line and is taxed at 0%. The other $18,900 is over the line and pays 15%, which comes to $2,835. Across the whole gain that's about 5.7%.

The chart puts the same $50,000 gain on top of different amounts of other income.

Ordinary income after the deductionGain taxed at 0%Gain taxed at 15%
$0$50K$100K$150K$200K$40,000$60,000$80,000$100,000$120,000$140,000$160,000Other income before the standard deduction0% ends at $98,900
A $50,000 long-term gain for a married couple under 65 in 2026, stacked on seven levels of other income. The height of each bar is taxable income. The tax on the gain runs from nothing, with $80,000 or less of other income, to $7,500 once ordinary income alone passes the line.
Other income before the standard deductionOrdinary income after the deductionGain taxed at 0%Gain taxed at 15%
$40,000$7,800$50,000$0
$60,000$27,800$50,000$0
$80,000$47,800$50,000$0
$100,000$67,800$31,100$18,900
$120,000$87,800$11,100$38,900
$140,000$107,800$0$50,000
$160,000$127,800$0$50,000
A $50,000 long-term gain for a married couple under 65 in 2026, stacked on seven levels of other income. The height of each bar is taxable income. The tax on the gain runs from nothing, with $80,000 or less of other income, to $7,500 once ordinary income alone passes the line.

Stacking has a side effect that catches people out. Once a gain straddles the line, every extra dollar of ordinary income pushes a dollar of gain from 0% up to 15%. If Sam and Jordan took another $1,000 from the IRA that year, they'd pay 12% on the withdrawal and 15% on the $1,000 of gain it lifted over the line: $270 on $1,000, in what looks like the 12% bracket.

Try your own figures: where a gain lands, what it costs, and what the next $1,000 of ordinary income would cost on top of it.

Filing as
Gain taxed at this rateTax on it
$0$10K$20K$30K$40K0%15%20%Rate on the gain
How much of a long-term gain is taxed at 0%, 15% and 20% in 2026, stacked on the ordinary income you choose, for someone under 65 taking the standard deduction. Each pair of bars is one rate: the gain taxed at it, and the tax on that gain.
Rate on the gainGain taxed at this rateTax on it
0%$31,100$0
15%$18,900$2,835
20%$0$0
$100,000
$50,000

After the standard deduction, ordinary income fills $67,800 of taxable income and the gain sits on top. $31,100 of the gain is taxed at 0%, $18,900 at 15%. The tax on the gain is $2,835, 5.7% of it. Another $1,000 of ordinary income would cost $270: $120 on the income itself and $150 on gain it pushes into a higher rate.

How much of a long-term gain is taxed at 0%, 15% and 20% in 2026, stacked on the ordinary income you choose, for someone under 65 taking the standard deduction. Each pair of bars is one rate: the gain taxed at it, and the tax on that gain.

The 3.8% tax on top

Above $200,000 of modified AGI for a single filer or $250,000 for a couple, the net investment income tax adds 3.8% to gains, dividends and interest, so the top federal rate on a long-term gain is 23.8%. One large sale can put a household over the threshold for a single year. How retirement income is taxed has a worked example.

Dividends and fund distributions

Two kinds of investment income show up every year whether you sell or not.

The first is dividends. A qualified dividend is taxed at the long-term rates above, and stacks the same way. Most dividends from US companies qualify if you held the stock for more than 60 days of the 121-day period that starts 60 days before the ex-dividend date. Ordinary dividends are taxed at your bracket rate. Those include interest paid out by bond funds and money market funds, and most dividends from real estate investment trusts.

The second is capital-gain distributions. When a mutual fund sells holdings at a profit, it has to pass the net gain on to its shareholders, usually in December. These distributions are always long-term gains to you, however long you've owned the fund, and they're taxable even when reinvested. So buying a fund in a taxable account just before its year-end distribution means paying tax on gains you never enjoyed: the share price drops by the amount paid out, and you get part of your own money back as taxable income. A fund with heavy turnover can also hand you a tax bill in a year when its price fell. Index funds and ETFs distribute far less.

Harvesting losses

Selling an investment for less than you paid produces a capital loss. Losses first cancel gains. If losses are left over, up to $3,000 per year ($1,500 if married filing separately) comes off ordinary income, and the rest carries forward to later years until it's used. Tax-loss harvesting means selling a holding that's down, on purpose, and buying something similar so your investments barely change. The taxable account has an example of one year's saving. What follows is the rule that limits it, and the tax that comes back later.

The wash-sale rule

The loss is disallowed if you buy the same or a "substantially identical" investment within 30 days before or after the sale, a 61-day window in all. The rule reaches further than your own brokerage account:

  • A purchase by your spouse counts, and so does one by a corporation you control.
  • A purchase inside your IRA or Roth IRA counts. The IRS ruled on this in 2008 (Revenue Ruling 2008-5).
  • A contract or option to buy counts as a purchase.
  • Automatic purchases count: a reinvested dividend, or a regular contribution that buys the same fund in another account.

In an ordinary wash sale the loss isn't gone for good. It's added to the basis of the replacement shares, and their holding period picks up the old shares' holding period, so you get the loss when you eventually sell them. The IRA case is worse. The 2008 ruling says the IRA's basis isn't increased, so the loss is simply lost.

The rule applies to losses only. You can sell at a gain and buy back the same day.

Why it mostly defers tax

The replacement shares start with a lower basis than the ones you sold, lower by exactly the loss you took. When you sell them one day, the gain is larger by the same amount. So harvesting moves tax to a later year. Whether any of it goes away for good depends on what happens to the replacement shares.

What happens to the replacement sharesTax saved nowExtra tax laterNet saving
Sold later, with the gain taxed at 15%$1,980$1,350$630
Sold in a year with room at 0%$1,980$0$1,980
Held until death, or given to charity$1,980$0$1,980
A $9,000 loss harvested by someone in the 22% bracket with no gains to offset: $3,000 comes off ordinary income in each of three years. The replacement fund's basis is $9,000 lower, so $9,000 of extra gain is waiting when it's sold.

If the loss only cancels long-term gains that would have been taxed at 15% and the later gain is taxed at 15% too, all you've gained is time. And if your gains this year would have been taxed at 0% anyway, a harvested loss used against them saves nothing and still lowers your basis.

The $3,000 limit is a fixed dollar amount, not adjusted for inflation. A carryforward doesn't expire while you're alive, but it can't be inherited.

Harvesting gains at 0%

Gain harvesting is the mirror image. In a year when your taxable income is under the 0% line, you sell shares with a long-term gain and buy them straight back. There's no federal tax on the gain and no waiting period, and the shares now carry today's price as their basis. Later growth is still taxable, but the gain up to now never will be. The typical window is early retirement, after the paychecks stop and before Social Security and required withdrawals begin.

How much room you have is simple to work out: the 0% line minus your taxable ordinary income. A couple under 65 with $60,000 of ordinary income has $27,800 of it taxable after the deduction, which leaves $71,100 of gain at 0%.

A gain taxed at 0% is still income, though. It raises your AGI by the full amount, and several other things key off AGI.

  • Social Security: a gain counts toward the income test that decides how much of your benefit is taxable, so it can pull more of the benefit into tax at ordinary rates.
  • ACA premium credits: before 65, if you buy health insurance on the marketplace, your credit shrinks as income rises and stops completely above 400% of the poverty line: $62,600 for one person and $84,600 for a couple for 2026 coverage. A gain that takes you a dollar over costs the whole credit. Health cover before 65 has the numbers.
  • Medicare premiums: the income surcharge known as IRMAA looks at your income from two years earlier. At 2026 rates, the first tier starts above $109,000 single or $218,000 joint and adds about $1,148 per person per year. Gains at 63 or later can land there. See IRMAA.
  • State tax: most states tax a capital gain as ordinary income and have no 0% rate. State taxes covers which ones don't.

The Social Security effect is the least obvious. Take a married couple, both 67, with $48,000 of Social Security and $30,000 of IRA withdrawals. Before any gain they owe no federal tax: $14,500 of their benefits is taxable, and their $47,500 of deductions more than covers their income. The chart shows what each extra dollar of long-term gain costs them.

Tax on the next dollar of gainRate on the gain itself
0%5%10%15%20%$0$15K$30K$45K$60K$75K$90K$100KLong-term gain realized
Federal tax on each extra dollar of long-term gain in 2026 for a married couple, both 67, with $48,000 of Social Security and $30,000 of IRA withdrawals. The dotted line is the capital-gains rate. The gap between the lines is tax on Social Security benefits that the gain pulled into income, and further right, the senior deduction phasing out.
Long-term gain realizedTax on the next dollar of gainRate on the gain itself
$00%0%
$5K8.5%0%
$10K8.5%0%
$15K8.5%0%
$20K8.5%0%
$25K8.5%0%
$30K8.5%0%
$35K0%0%
$40K0%0%
$45K0%0%
$50K0%0%
$55K0%0%
$60K0%0%
$65K0%0%
$70K0%0%
$75K0%0%
$80K18%15%
$85K18%15%
$90K18%15%
$95K18.24%15%
$100K18.24%15%
Federal tax on each extra dollar of long-term gain in 2026 for a married couple, both 67, with $48,000 of Social Security and $30,000 of IRA withdrawals. The dotted line is the capital-gains rate. The gap between the lines is tax on Social Security benefits that the gain pulled into income, and further right, the senior deduction phasing out.

A $35,000 gain is entirely inside their 0% band, and no capital-gains tax is due on it. But it lifts the taxable part of their Social Security from $14,500 to the maximum, $40,800, and their federal tax goes from nothing to $2,330. That's 6.7% of the gain. The next $40,000 of gain adds no federal tax at all, because their benefits can't become any more taxable. A harvest is worth doing when the tax it triggers elsewhere is smaller than the tax it saves later, and working that out takes the whole return.

Gain harvesting also competes with Roth conversions for the same low-income years, since conversion income fills the stack from the bottom and pushes gains up. Which account to draw from first and Roth conversions cover that trade.

Homes, collectibles and rental property

A few assets have their own rules.

  • Your home: if you owned and lived in it for at least two of the five years before the sale, up to $250,000 of gain is excluded from income, or $500,000 on a joint return. You can generally use the exclusion once every two years. A surviving spouse who hasn't remarried keeps the $500,000 figure for a sale within two years of the death. Gain above the exclusion is a long-term gain like any other, and a loss on your own home isn't deductible.
  • Collectibles: long-term gains on coins, art, antiques and precious metals are taxed at your ordinary rate, capped at 28%.
  • Rental property: the depreciation you deducted while you owned the building comes back when you sell. That part of the gain is taxed at your ordinary rate up to a maximum of 25%, and only the rest gets the 0%, 15% and 20% rates.

Step-up at death, and gifts

What happens to a gain when shares change hands depends on how they change hands.

At death, the basis of what you own resets to its value on that day, the step-up in basis. The gain that built up in your lifetime is never taxed, and your heirs are treated as long-term holders from the first day. It works downward too: shares worth less than you paid get the lower value as their basis, and the loss disappears. Retirement accounts get no step-up. Beneficiaries and estate basics covers jointly owned and community property.

A gift during your life carries your basis and your holding period with it. If you give Nora shares you bought for $2,000 that are now worth $10,000, she owes tax on the $8,000 when she sells. That can work in the family's favor if her income puts the gain in the 0% band. It doesn't work for children under 19, or full-time students under 24: the "kiddie tax" taxes their investment income above $2,700 (for 2026) at the parents' rates. For 2026 you can give $19,000 per person without filing a gift tax return.

Shares that have lost value make a poor gift. The recipient can't use your loss, because for figuring a loss their basis is the value on the day of the gift. Sell them yourself, take the loss, and give the cash.

A gift to charity of shares held more than a year avoids the gain altogether. Giving in retirement works through an example.

For an older investor with more than they'll spend, these rules favor selling the high-basis lots for cash and keeping the lowest-basis shares for heirs or charity.

Common mistakes

  • Selling a few days short of one year. On a $10,000 gain in the 22% bracket, a short-term sale costs $2,200 and a long-term one $1,500, or nothing in the 0% band.
  • Leaving the lot method on its default, so the oldest and cheapest shares are sold first.
  • Tripping the wash-sale rule with a reinvested dividend, a purchase in an IRA, or a spouse's account buying the same fund.
  • Harvesting a gain at 0% without checking Social Security, ACA credits, Medicare premiums and state tax.
  • Harvesting a loss in a year when your gains would have been taxed at 0% anyway.
  • Buying a mutual fund in a taxable account in early December, just ahead of its distribution.
  • Leaving reinvested dividends out of the basis of old shares, and so paying tax on them twice.
  • Giving away shares that are at a loss.

Seeing it in your own plan

Income Tax, in retirement mode, takes a brokerage withdrawal and the share of it that's gain. It stacks the gain on your other income, shows how much falls at 0%, 15% and 20%, works out how much of your Social Security becomes taxable, and adds the 3.8% tax and your state's tax. To test a gain harvest, raise the gain and watch the total tax as well as the capital-gains line. If the total moves while the gain is still inside the 0% band, one of the side effects above is the cause.

Healthcare shows the ACA credit at each income before 65. The Withdrawal Order optimizer runs the larger question of which account to draw on each year across a whole retirement.

Common questions

If I reinvest the money straight away, do I still owe tax on the gain?

Yes. A sale in a taxable account is taxed whatever you do with the proceeds. Moving from one fund to another is a sale of the first. Only inside a retirement account can you switch investments without tax.

Does the wash-sale rule apply when I sell at a gain?

No. It only disallows losses. You can sell at a gain and buy the same shares back immediately, which is what makes gain harvesting possible.

Do my capital losses ever expire?

Not while you're alive. Unused losses carry forward year after year, offsetting gains and then up to $3,000 of ordinary income each year. They can't be passed to heirs, so a large carryforward late in life is a reason to realize gains against it.

Is all of a mutual fund's year-end payout a capital gain?

Not necessarily. Funds pay out dividends and capital gains separately, and Form 1099-DIV lists each: ordinary dividends, the qualified part of them, and capital-gain distributions. Only the last is always treated as a long-term gain.

In short

  • The gain on a sale depends on which lots you sell; specific identification lets you choose, and it has to be chosen at the time of the sale.
  • Long-term gains stack on top of ordinary income and are taxed at 0% up to $98,900 of taxable income for a couple in 2026 ($49,450 single), then 15%, then 20%.
  • A harvested loss offsets gains and $3,000 of income per year, but it lowers your basis, so it mostly moves tax to a later year.
  • A wash sale, including one through an IRA or a spouse's account, disallows the loss.
  • A gain at 0% still raises AGI, which can make Social Security taxable, cut ACA credits, raise Medicare premiums and draw state tax.

Try it

Enter a brokerage withdrawal and the share of it that's gain to see how much lands at 0%, 15% and 20%.

Open the tool

Key terms

Lot
The shares bought in one purchase, with their own cost and date. Which lots you sell decides the gain you report.
Specific identification
Telling the brokerage exactly which lots to sell, at the time of the sale, instead of letting the oldest go first.
Tax-loss harvesting
Selling an investment at a loss to offset gains and up to $3,000 of other income per year, and buying something similar in its place.
Tax-gain harvesting
Selling at a gain in a year when the gain is taxed at 0%, then buying back, so the shares carry a higher basis from then on.
Next: Giving in retirementNext lesson

Lessons explain how things work. They aren’t personal financial, tax or legal advice.

Try it

Enter a brokerage withdrawal and the share of it that's gain to see how much lands at 0%, 15% and 20%.

Open the tool

Key terms

Lot
The shares bought in one purchase, with their own cost and date. Which lots you sell decides the gain you report.
Specific identification
Telling the brokerage exactly which lots to sell, at the time of the sale, instead of letting the oldest go first.
Tax-loss harvesting
Selling an investment at a loss to offset gains and up to $3,000 of other income per year, and buying something similar in its place.
Tax-gain harvesting
Selling at a gain in a year when the gain is taxed at 0%, then buying back, so the shares carry a higher basis from then on.