Nobody likes losing money on an investment, but if you wind up taking a loss, there's often a small silver lining: You can use that loss to offset gains from your more profitable investments, thus lowering the amount of taxes you end up having to pay. However, there is an exception to this rule, and it's known as a wash sale. A wash sale is the sale of a security (such as a stock or a bond) at a loss followed by the repurchase of the same security, or one that's substantially identical, within 30 days of the sale.

Sell Stock

IMAGE SOURCE: GETTY IMAGES.

The wash-sale rule

The wash-sale rule was established to prevent investors from "cheating" and claiming the benefits of short-term losses. Under the rule, you can't claim a loss on the sale of a security if you repurchase it (or buy one that's substantially identical) within 30 days of selling it.

Let's say you buy 1,000 shares of Company X's stock but the price then falls to $7 per share. If you sell off all of your shares on Dec. 1, you can take a $3,000 loss for tax deduction purposes provided you don't repurchase that same stock for at least 30 days following the sale. However, if on Dec. 20 you decide to repurchase 100 shares of Company X's stock, your original loss won't count for tax purposes, which means you won't be able to use it to offset your investment gains.

The wash sale period is actually 61 days long, starting 30 days before the date a stock is sold and lasting 30 days after the sale. What this means is that if you're planning to sell 100 shares of Company X's stock at a loss on Dec. 1, you can't buy an additional 100 shares on Nov. 20 in anticipation and expect to still claim that loss for tax purposes. Furthermore, if you sell shares at a loss and your spouse or a company you control buys those same shares back within 30 days of the sale date, it's also considered a wash sale.

Substantially identical securities

Generally speaking, the IRS doesn't consider securities of one company substantially identical to those of another. So if you sell 100 shares of Company Y, which is a tech stock, at a loss, and buy 100 shares of Company Z, also a tech stock, within 30 days, the wash sale rule does not apply. Similarly, a company's bonds and preferred stock are usually not considered substantially identical to that same company's common stock.

Limited financial benefit

Though you can't claim a loss from a wash sale, you may be able to derive some financial benefit from it by adding your loss to the cost basis of the new shares you purchase. Let's say you sell 100 shares of Company X's stock at a $3,000 loss but then repurchase those shares within 30 days. While you can't claim that $3,000 loss, you can add that amount to the cost basis of your new shares. Normally, your cost basis is calculated by multiplying the price per share by the number of shares purchased. Adding in your loss increases your cost basis, which may be beneficial from a tax perspective. If you sell those new shares at a profit, your capital gains will appear lower because you'll have "spent more" to buy those shares. Similarly, if you sell those new shares at a loss -- one you're allowed to record because the wash sale rule doesn't apply -- your losses will appear higher.

If your goal is to reduce your tax burden by selling shares at a loss, it's important to pay attention to the dates of your wash sale period. Waiting a few extra days to make a move could spell the difference between claiming a tax loss and losing out on the option to do so. 

This article is part of The Motley Fool's Knowledge Center, which was created based on the collected wisdom of a fantastic community of investors. We'd love to hear your questions, thoughts, and opinions on the Knowledge Center in general or this page in particular. Your input will help us help the world invest, better! Email us at knowledgecenter@fool.com. Thanks -- and Fool on!

Try any of our Foolish newsletter services free for 30 days. We Fools may not all hold the same opinions, but we all believe that considering a diverse range of insights makes us better investors. The Motley Fool has a disclosure policy.