A wash sale occurs when you sell a security for a loss, then turn around and buy it (or something very similar) again within 30 days. The wash sale rule is an IRS regulation put in place to prevent you from taking a tax deduction for the security sold in the wash sale.
The IRS created this in order to discourage investors from selling their losing trades at the end of the tax year—in order to use the losses to offset their capital gains—only to then buy back the stock again a couple of days later in the new year.
Keep in mind that a wash sale by itself is not against the law. Problems with them only occur if you claim the tax loss on your taxes. Tax software will generally calculate was sales correctly if they are made in the same account, though if the trades are made in different accounts, including those of a spouse, the calculations would have to be made manually. A tax accountant should recognize wash sales and adjust for them.
Let's say you buy 100 shares of XYZ for $20, but at the end of December it is trading at $15. You sell the stock at a $500 loss. However, two weeks later the stock has fallen to $12, and you think it is undervalued so you buy it back.
What happens now?
You created a wash sale when you bought the stock back within the 30-day window. That's fine. You just can't claim that $500 loss on your taxes for that year. Instead, what happens is the $500 loss is added to your cost basis of the new trade. Your purchase at $12 will be recalculated to show you bought it at $17. Additionally, the length of time that you owned the first trade will be added to the second trade.
The only negative thing the wash sale does is to disallow claiming the loss at the current time. But, since you add the loss to your current trade you effectively lower the amount of taxable gains in the future. You haven't lost the ability to claim the losses from the first trade, you've only transferred them to the second trade. Which means, in the end, all the wash sale rule has done is pushed your timeframe forward for calculating your gain or loss on your XYZ stock.
Again, the purpose for this rule is not to harm a trader or investor, it is to close a tax loophole. It was put in place to stop people from selling all their losing trades at the end of December only to buy them back the first trading day in January.
Something worth noting is that the wash sale rule only applies to securities. The US government has so far been afraid to classify cryptocurrencies as securities because they know that would lend them considerable credibility. Effectively, the government would be admitting that cryptocurrency is a competing currency to the US dollar. Because they won't call it a security, and instead call crypto property, traders/investors are free to harvest losses all they want. If you bought Bitcoin for $40,000, and the price dropped to $30,000, you could sell it, then almost immediately buy it back. You could then use that $10,000 loss to offset any crypto gains for tax purposes (keep in mind the gov't doesn't want to recognize cryptocurrencies, but that doesn't mean they don't want some tax money from it). This rule, or lack thereof, is constantly being brought up in government, so it may not last for much longer.
Keep in mind that we are not tax accountants, and this is not tax advice. Most of this won't matter for the average trader, but if you actively trade stocks and crypto we'd encourage you to seek out the help of an accountant familiar with wash sales and tax-loss harvesting.