← Back to blog

The Wash Sale Rule: How the 30-Day Window Works

October 24, 2026
The Wash Sale Rule: How the 30-Day Window Works

The wash sale rule says you can't deduct a loss on a stock or security if you buy the same or a substantially identical one within 30 days before or 30 days after the sale. Under Section 1091 of the Internal Revenue Code, that makes a 61-day window: the 30 days before, the day of the sale, and the 30 days after. The loss isn't erased. It is postponed and added to the cost basis of the shares you bought back. The details of what counts as a repurchase, though, catch a lot of careful investors.

Oracleinvestments
Compare Stocks Beyond Tax Timing
Oracle Investments scores over 260 stocks on fundamentals and lets you compare companies side by side as you review your portfolio.
Explore stock analysis

TL;DR

  • A wash sale happens when you sell at a loss and buy the same or a substantially identical security inside the 61-day window around the sale.
  • The loss is deferred, not lost: it is added to the basis of the replacement shares, and you get the benefit when you finally sell those.
  • The rule follows you across accounts. Buying back inside an IRA can make the loss permanently unusable.
  • To avoid a wash sale, wait out the full 30 days, or move into an investment that is similar but not substantially identical.
  • Wash sales are reported on Form 8949 with code W.

Table of Contents

What the wash sale rule actually says

The rule is a tax accounting provision. Investor.gov describes a wash sale as selling or trading securities at a loss and, within 30 days before or after, buying substantially identical securities or acquiring them in a fully taxable trade. The statute and the implementing regulation both start from the same place: a taxpayer can't deduct a loss from a sale of stock or securities when that triggering purchase happens.

The logic is economic substance. If you sell a stock on Tuesday to book a loss and buy it back on Wednesday, your position hasn't changed. You still own the same company in the same amount. NerdWallet's explainer notes that the rule exists to stop investors from manufacturing tax losses without really changing their market exposure.

Two points readers often get wrong:

  • It isn't illegal. Triggering a wash sale doesn't break a law or invite a penalty by itself. It simply defers the deduction, per the same NerdWallet piece.
  • It only applies to losses. If you sell at a gain and buy back the next day, nothing special happens. You owe tax on the gain.

The 61-day window, day by day

People call it the 30-day rule, but the window is wider than that name suggests. It has three parts:

  1. The 30 days before the sale date.
  2. The sale date itself.
  3. The 30 days after the sale date.

That means a purchase made before you sell can trigger the rule. Say you buy 50 more shares of a stock on June 10 and then sell your older, higher-priced 100 shares at a loss on June 25. Those June 10 shares were acquired within 30 days before the sale, so part of the loss can be disallowed.

The practical consequence: it isn't enough to avoid buying after you sell. You need to check recent purchases, including automatic ones.

Watch your automatic buys

Dividend reinvestment plans and recurring purchases are the most common accidental triggers. A reinvested dividend is a purchase. If you sell shares at a loss and a dividend reinvests into the same stock 12 days later, you may have a wash sale on that small slice. Turn off reinvestment on a position before you harvest a loss from it, and keep it off through the end of the window.

A worked example

Here is a simple illustration with made-up numbers.

You buy 100 shares of a stock at $50, a $5,000 cost. The price falls to $40 and you sell all 100 shares for $4,000, a $1,000 loss. Ten days later the stock is at $42 and you buy 100 shares back for $4,200.

Because you bought within 30 days, the $1,000 loss is disallowed for now. It is added to the cost basis of the new shares:

ItemAmount
Price paid for replacement shares$4,200
Disallowed loss added to basis$1,000
Adjusted cost basis of replacement shares$5,200

If you later sell those shares for $5,500, your taxable gain is $300 rather than $1,300. The deferred loss comes back as a smaller gain or larger loss at that point. The deduction was delayed, not destroyed.

When you only buy back part

The rule works share by share. If you sell 100 shares at a $1,000 loss and buy back only 40, the disallowed portion is generally the loss attributable to those 40 shares, here $400. The remaining $600 loss is still deductible. Your broker's cost basis reports normally track this, but check them against your own records.

What counts as "substantially identical"

This is where the rule gets fuzzy. The IRS doesn't publish a complete list of what is substantially identical, according to the NerdWallet guide. Some cases are clear:

  • Selling a stock and repurchasing the same ticker is covered.
  • The rule also reaches contracts and options on the security. TurboTax's help page lists them alongside stocks and securities.

Other cases are judgment calls:

  • Two funds that track the same index. Swapping one S&P 500 fund for another from a different provider is the classic gray area. Holdings overlap almost completely, and the IRS could view them as effectively the same.
  • Funds tracking different indexes. Moving from a total-market fund to a large-cap growth fund is a different exposure. Many experts see this as a way to stay invested while the window runs, though the definition remains subjective and interpreted by the IRS.
  • Different companies in the same industry. Selling one bank stock and buying another bank stock is generally a different company, which is why this is a common approach. It still changes your exposure, so it should fit your plan, not just your tax return.

If the stakes are high, such as a large loss or a complicated position, ask a CPA or enrolled agent before relying on any swap.

Same account, other accounts, and your IRA

The rule isn't limited to one brokerage account. If you sell at a loss in a taxable account at one firm and buy the same stock at another firm, it still counts. Your broker may only see its own side, so the burden of tracking cross-account trades falls on you.

IRAs deserve special attention. In Revenue Ruling 2008-5, the IRS held that a wash sale can occur when you sell at a loss in a taxable account and buy back inside an IRA. The consequence is harsher than usual. With a normal wash sale the loss moves into the basis of the new shares. In an IRA, you can't increase basis that way, so the tax benefit of the loss is permanently forfeited. Kitces walks through the same ruling.

If you manage both taxable and retirement money, that matters. Automatic contributions into an IRA that buy the same fund you just sold at a loss can quietly cancel the deduction. Readers who hold more unusual assets in retirement accounts, such as property, may find this self-directed IRA real estate checklist helpful for understanding how those accounts are structured.

Same account, other accounts, and your IRA — overview diagram

Who and what the rule doesn't cover

Dealers

The statute carves out losses sustained in the ordinary course of business as a dealer in stock or securities, per Section 1091. That is a narrow exemption for people who are dealers, not a general pass for frequent traders. Active traders who want to be treated differently for tax purposes should discuss it with a tax professional before making any election.

Cryptocurrency

As of 2026, the wash sale rule does not apply to crypto, because the IRS classifies it as property rather than a security, according to TurboTax. That could change through future law or guidance, so check current IRS information before you plan around it. Digital assets are still reportable on Form 8949.

Gains

The rule is about losses only. Gains are taxed whether or not you repurchase.

How to avoid a wash sale

You have a few honest options, each with a trade-off.

  1. Wait 31 days. Sell, then stay out of the same security, and don't buy it anywhere (including your IRA or via reinvested dividends) until the window has cleared. The cost is being out of the market if the stock rebounds.
  2. Swap into something similar but not identical. For example, a different company in the same sector, or a fund that tracks a different index. You keep some market exposure, but you take on tracking differences and the "substantially identical" risk.
  3. Buy first, sell later. Some investors add to a position and wait more than 30 days before selling the original lot. You carry more risk during the wait.
  4. Sell and don't come back. If the reason you sold is that the thesis broke, the wash sale issue never arises. A tax loss is a bonus, not a reason to hold or exit.

A tax-driven sale should be a decision about the investment first. Our guide on tax loss harvesting for U.S. investors covers the mechanics, and when to sell stocks covers the question that should come before any tax move.

A year-end checklist

  • List every position you plan to sell at a loss.
  • Search your last 30 days of purchases, in every account you and your household use.
  • Switch off dividend reinvestment and automatic buys for those tickers.
  • Decide on your replacement: wait, or choose a different, not substantially identical holding.
  • Put the repurchase date on your calendar, a full 31 days after the sale.

Selling in late December is a trap if you plan to buy back in early January. A repurchase inside 30 days still falls in the window even though the tax year changed.

Reporting a wash sale on your return

Brokers report sales on Form 1099-B and often flag wash sales they can see, but you report them on Form 8949 and Schedule D. Per the Form 8949 instructions, you enter code W in column (f) and the disallowed loss as a positive amount in column (g). That keeps the loss out of this year's net result and moves it into the replacement shares' basis.

If your trades spanned accounts or firms, your broker's form may not reflect everything. Reconcile it yourself, and bring the records to a tax preparer if the numbers don't tie out.

Our perspective: scoring first, tax second

We build a stock-scoring app, so we see the wash sale rule from a particular angle: it matters most when investors let it drive the decision. The mistake we see in how people talk about it is treating a loss as a reason to trade. A loss is information about price. It says nothing by itself about whether the business is still sound.

Our perspective: scoring first, tax second — overview diagram

When you are weighing a sale, we'd start with the fundamentals: profitability, valuation and financial health. Oracle scores more than 260 stocks on exactly those and shows the inputs, so you can compare a stock you are thinking of selling against alternatives side by side. The scores are rule-based and built on reported company fundamentals, not model-driven guesses. If a replacement scores well on the same measures, it can be a reasoned swap during the 30-day window. If nothing else scores well, the better answer may be to wait out the window and hold the cash.

The value investors we draw on, such as Warren Buffett, Charlie Munger and Peter Lynch, are known for patience. Tax-loss trades fit that mindset only when they are deliberate and rare. Frequent churn creates wash sale paperwork, transaction costs and a risk of selling something good. If your concern is protecting a portfolio rather than harvesting a deduction, our piece on downside protection strategies is a better starting point.

— Matt

Checking the replacement before you buy

When you need a stand-in for a position you sold, compare on the criteria that matter, not just the sector label:

QuestionWhy it matters
Is it a different company or a different index?Same ticker or same index raises wash sale risk.
Do the businesses earn money the same way?Same sector doesn't mean same risk.
Is it priced reasonably against its fundamentals?A replacement bought only for tax reasons can be expensive.
Would you hold it past the window?If not, you may be swapping twice, with more tax paperwork.

Oracle's side-by-side comparison is built for the third question. You can see profitability, valuation and financial health for two companies at once, without building a spreadsheet. The Premium Annual plan adds real-time portfolio tracking. You can see how Oracle works on our site and decide whether it fits your routine. Note that Oracle doesn't give tax advice. It helps you evaluate the investment side of the decision.

FAQ

What happens if I sell a stock at a loss and buy it back?

If the repurchase falls within 30 days before or after the sale, the loss is disallowed for the current year. It is added to the basis of the replacement shares, so you realize the benefit when you sell them later. Report the sale on Form 8949 with code W.

Is a wash sale illegal?

No. It is a tax rule that postpones your deduction, not a violation that carries a penalty by itself. The only cost is delayed or, in an IRA, lost use of the loss.

Does the wash sale rule apply to my IRA or Roth IRA?

Yes. Under Revenue Ruling 2008-5, buying the same security in an IRA after selling it at a loss in a taxable account can trigger the rule. Because you can't add the disallowed loss to basis in the IRA, it is permanently lost. Talk to a tax professional if your accounts overlap.

Does the wash sale rule apply to crypto?

Not as of 2026, since the IRS treats crypto as property rather than a security. Check for new guidance before you rely on that, because the rules can change.

How do I avoid a wash sale?

Wait at least 31 days before repurchasing, or move into an investment that is not substantially identical, such as a different company or a fund tracking a different index. Also turn off dividend reinvestment on the position and check every account you control for recent purchases.

Sources