A wash sale occurs when you sell a security at a loss and then buy the same or a substantially identical security within 30 days before or after the sale. The IRS created the wash sale rule to prevent investors from claiming a tax loss while maintaining essentially the same investment position. When a wash sale occurs, the loss is disallowed for tax purposes in the current year, though it's added to the cost basis of the repurchased shares — so the loss isn't gone forever, it's just deferred. The wash sale rule applies across all your accounts, including IRAs, so you can't sell a stock in a taxable account and immediately repurchase it in a retirement account to sidestep the rule. Investors who practice tax-loss harvesting need to wait at least 31 days before repurchasing the same investment, or replace it with a similar but not identical position.