Skip to content

Tax-Loss Harvesting: The Math and the Wash-Sale Rule

A realized loss is worth real money at your marginal rate - if you avoid the 61-day wash-sale window. The full worked example, the substitution rules, and the honest caveats about what harvesting defers.

By the editorial team at The Long View How we check our guides 8 min read
A paper notebook with handwritten figures beside a calculator on a wooden desk near a window

When a fund you own drops, your brokerage shows a red number and your stomach shows a worse one. Tax-loss harvesting is the one technique that turns that red number into something useful: selling the position to lock in a loss the tax code will pay you for, staying invested with a similar - but not identical - fund, and resetting your cost basis lower along the way. The mechanics are simple; the mistakes, mostly around the wash-sale rule, are surprisingly easy to make. This guide walks the full worked example and then the rules that decide whether the tax saving is real.

Scope first: tax-loss harvesting only applies in taxable accounts. IRAs, 401(k)s, and other retirement accounts have no capital gains or losses to harvest - losses inside them produce no deduction. If your entire portfolio is tax-advantaged, this article describes a tool you do not need.

The core trade, in numbers

Here is the whole transaction with every figure stated. Suppose you bought 100 shares of a stock fund at $50 per share two years ago - a $5,000 position with a $5,000 cost basis. The fund falls to $38, so your position is worth $3,800 and shows a $1,200 unrealized loss. You sell, realizing that loss, and immediately put the proceeds into a different fund that tracks a different index - say, a total-market fund when you owned an S&P 500 fund. Your market exposure is essentially unchanged, but you now hold a documented $1,200 loss on your tax return.

What is that loss worth? It depends on what it offsets. Capital losses first cancel capital gains; $1,000 of long-term gains taxed at 15% would have cost you $150, so a $1,200 loss eliminates up to that much tax. If you have no gains, the loss moves to ordinary income, offsetting up to $3,000 per year: at a 24% marginal rate, that $1,200 loss is worth $288 in reduced tax. Any amount beyond the $3,000 limit does not disappear - it carries forward indefinitely to future years.

What the loss offsets Tax rate applied Value of a $1,200 loss
Long-term capital gains 15% $180
Short-term capital gains 24% $288
Ordinary income (up to $3,000/yr) 24% $288
Ordinary income (32% bracket) 32% $384

Notice the ordering rule buried in that table: short-term losses are most valuable because they first offset short-term gains, which are taxed at ordinary rates. Long-term losses first offset long-term gains at the lower 15% (or 20%) rate. The IRS nets them in that order regardless of your preference, which is why harvesting a recently purchased position - a short-term loss - is generally worth more than harvesting an old one.

The wash-sale rule: the one rule that voids the trade

The tax benefit exists on one condition: you did not buy back the same investment around the sale. Under the wash-sale rule, if you acquire a substantially identical security within 30 days before or after the sale - a 61-day window in practice - the loss is disallowed. It is not gone forever; it gets added to the cost basis of the repurchased shares. But you have achieved nothing except paperwork, and in an IRA, the disallowed loss vanishes entirely rather than being preserved.

The worked version of the mistake: suppose that instead of a total-market fund, you repurchased the same S&P 500 fund at $38 within the window. Your $1,200 loss is disallowed and your new basis becomes $3,800 + $1,200 = $5,000 - exactly $50 per share again. The transaction nets to zero, which is precisely what the rule is designed to prevent. The recovery math makes the cost of waiting visible: buying the replacement fund at $38 means it must rise about 31.6% to reach your old $50 cost, but your new total-market position still participates in the full recovery. Nothing about staying invested is lost by using a different fund.

What counts as "substantially identical"

This is the phrase that carries all the ambiguity, and the IRS has never published a bright-line definition. The safe, universally accepted moves: swapping between an S&P 500 index fund and a total-market index fund; between two funds from different providers tracking the same index is riskier - many practitioners treat two funds tracking the identical index as substantially identical, so treat that swap with caution; and selling one index fund while buying a fundamentally different asset class (say, a large-cap fund for an international fund) is clearly outside the rule. The clearly unsafe moves: selling an ETF and buying the same ETF's mutual-fund share class, swapping between share classes of the same fund, or letting an automatic investment plan or dividend reinvestment trigger a purchase inside the 61-day window - this last one is the most common accidental wash sale, because a $50 dividend reinvestment is enough to disallow the entire loss.

The automatic-purchase trap: before harvesting anything, turn off dividend reinvestment and pause scheduled purchases for the affected fund - in the brokerage and at the fund company if both exist. A payroll purchase into a 401(k) that holds the same fund does not trigger a wash sale (retirement accounts are separate), but a reinvested dividend in the taxable account does.

The honest caveats

Three things keep tax-loss harvesting from being free money. First, it mostly defers tax rather than eliminating it: your new fund has a $3,800 basis, so when you eventually sell its gains are measured from there. The benefit is the timing difference plus any rate arbitrage - harvesting a short-term loss now and paying long-term rates much later - which is real but modest. Second, the tax saving competes against the transaction's own frictions: bid-ask spreads, any transaction fees, and the risk that your replacement fund lags the original during the 30-day blackout (index-tracking risk is small but not zero). Third, the strategy's value concentrates in years when markets fall - which is also when you are least inclined to open your brokerage account. Run the arithmetic like the tables above before assuming the benefit beats the friction; the same show-your-work habit applies to any tax move, including the bracket arithmetic in how tax brackets actually work.

There is also an investor-behavior angle worth naming: harvesting institutionalizes the act of selling things that are down, which for many people is a healthy ritual that prevents panic-selling into cash. The loss you realize on paper was real the moment the market fell; the tax code simply gives you a receipt for it. That framing - and the long-run cost of fleeing to cash during drawdowns - is covered from the behavioral side in the behavior gap between investor and investment returns.

Carryforwards: the loss that waits for you

Because the ordinary-income offset caps at $3,000 per year, big harvests arrive in installments, and the carryforward schedule is worth writing down. Suppose a bad year leaves you with a $5,000 net loss beyond any gains. This year's return uses $3,000 against ordinary income; the remaining $2,000 carries forward. If next year you realize $4,000 of long-term gains, the carryforward absorbs them first - $4,000 of gains that would have cost $600 at a 15% rate produce no tax bill at all. The carryforward persists year after year with no expiration, surviving job changes and account transfers, and it reappears on line 14 of your Schedule D each year until used. Keep your own tally anyway; brokerage tax reports recompute it, but they occasionally miss losses realized at a previous firm.

One subtlety in the same return: losses and gains do not just net in one pot. Short-term losses offset short-term gains first, long-term losses offset long-term gains first, and only the leftovers cross over to the other category. That ordering is why the calendar of your sale dates - which side of the one-year mark each lot falls on - matters as much as the size of the loss, and why the "specify lots" choice at sell time is the highest-leverage checkbox in the whole process.

When harvesting is the wrong move

The reflex deserves its own counterweight. In a low-income year - a sabbatical, early retirement, a business loss - long-term gains may fall in the 0% capital gains bracket, and realizing gains at 0% while your bracket is low is better than harvesting losses you will spend against future income at 12% or 22%. For heirs, the basis reset at death can erase embedded gains entirely, which makes aggressive harvesting late in life with highly appreciated positions a trade worth pricing before assuming. And if the only "similar" replacement fund you can find charges meaningfully higher fees than your current one, the annual expense drag can quietly consume a one-time tax saving - a slow leak of exactly the kind the expense-ratio arithmetic in what an expense ratio actually costs you measures. Harvest when the tax arithmetic is genuinely in your favor, not because December arrived.

A practical year-end routine

For a do-it-yourself taxable portfolio, the routine is short. Once or twice a year (December is common, but any month works), list your taxable lots with unrealized losses and their holding periods. Short-term losses first, since they offset ordinary-taxed gains. Realize what you can use this year, remembering the $3,000 ordinary-income cap and any carryforward you already hold. Swap into the pre-selected replacement fund - chosen in advance, on a calm day, so you are not choosing replacements in a red market. Turn dividend reinvestment back on after the 61-day window closes, and record the new basis. If your lots are large or your tax situation has moving parts - stock compensation, a home sale, a business - this is the point where a one-hour session with a tax professional earns its fee, because the interaction rules outrun any article. And the software shortcuts have their own traps: broker "tax optimizer" tools default to average-cost lot accounting, which can harvest less than specific-lot selection would, so learn the "specify lots" option in your brokerage's sell dialog before December.

Losses are a cost of investing that arrives anyway. Harvesting does not change the market outcome; it just refunds a slice of the damage at your marginal rate and lowers the basis you will be taxed on later. Done deliberately, it is one of the few year-end rituals with a measurable dollar value attached.

This article is general tax and investing information, not personalized tax, legal, or investment advice. Tax rules, thresholds, and rates change; verify current rules with the IRS or a qualified tax professional before acting.