How the 30-day rule works
A loss is disallowed when the same stock is bought within 30 days before or after the sale; it moves into the new shares' basis.
The rule in Publication 550's words
"A wash sale occurs when you sell or trade stock or securities at a loss and within 30 days before or after the sale you: buy substantially identical stock or securities, acquire substantially identical stock or securities in a fully taxable trade, acquire a contract or option to buy substantially identical stock or securities, or acquire substantially identical stock for your individual retirement arrangement (IRA) or Roth IRA." The disallowed loss is added to the cost of the new shares, except in the IRA case, and their holding period includes the old shares'. Where you buy more or fewer shares than you sold, "match the shares bought in the same order that you bought them, beginning with the first shares bought" (IRS Publication 550, for 2025 returns, read 25 October 2026).
The year-end wash sale
Sell at a loss in December, buy back in January, and the loss leaves that year's return.
An example in dates
Sell 100 shares at a $2,000 loss on Monday 14 December 2026 to harvest it, and buy them back on Tuesday 5 January 2027: the buy is 22 days after the sale, inside the window, so the $2,000 isn't deductible for 2026. It is added to the January shares' basis and deducted when they are sold. Waiting until Thursday 14 January 2027, 31 days after, keeps the 2026 loss.
What a checker can't see
Buys in your other accounts, your IRA, or by your spouse count too; brokers report wash sales within one account.
Accounts, options and the exceptions
Publication 550 counts purchases for your IRA or Roth IRA (the loss is then lost, not deferred), and purchases by your spouse or a corporation you control. Options to buy the stock count; commodity futures and foreign currencies are outside the rule. A trader with a timely section 475(f) mark-to-market election isn't subject to it for trading securities (IRS Topic no. 429); see the trader tax status checker. This page is arithmetic over the trades you enter, not tax advice.