Investors looking to write off any capital losses need to beware of wash sales, which can derail their attempt to claim a deduction during tax time. A wash sale is one of the key pitfalls to avoid when trying to take advantage of tax-loss harvesting to reduce your taxes, and in falling markets it can be valuable to make sure you don’t run afoul of the rules.

Here’s what a wash sale is and how to easily avoid it while securing your tax write-off.

What is a wash sale?

A wash sale is when you sell an asset, such as a stock or bond, for a loss but have purchased the same asset or a very similar one within 30 days before or after the sale. A wash sale makes it appear as if you have sold your position and disowned the property, though you really haven’t.

If you’re claiming to have lost money on the sale of an asset, but it’s actually part of a wash sale, the Internal Revenue Service (IRS) disallows you from claiming a write-off on your tax return until you fully exit the position.

The wash-sale rule applies to stocks, bonds, mutual funds, ETFs, options, futures and warrants.

However, the wash-sale rule does not apply to cryptocurrency, at least not yet. So crypto traders who are looking to claim a tax deduction can literally sell their investment and immediately repurchase it and still get to take advantage of tax-loss harvesting.

How to avoid violating the wash-sale rule

Normally, the IRS allows you to write off your capital losses, and you can use losses to offset any capital gains. In fact, in any given year you can write off a net loss of up to $3,000, if you have eligible losses. That is, tax rules allow you to more than offset any gains. Savvy investors strategically use losses to minimize their taxable income through tax-loss harvesting.

If you have a wash sale, however, you cannot claim the write-off until you finally sell the asset and avoid repurchasing it for at least 30 days. After that period, you can re-buy the asset without triggering the wash-sale rules. Of course, if you lose money on this repurchase and sell it yet again, you’ll have to wait another 30 days before repurchasing the asset to avoid a wash sale.

Don’t fret that you’ll lose your tax break forever due to the wash-sale rule, however. The ability to claim your loss is only deferred, not eliminated. Simply do not re-buy the asset in the 30-day window, and you can safely claim the loss on your tax return and without any further penalty.

4 sneaky wash-sale workarounds that won’t work

Investors sometimes think they can work around the wash-sale rule through a variety of clever measures, but the IRS regularly disallows these maneuvers. Here are a few of the most popular.

1. You sell for a loss, while your spouse buys

The wash-sale rule applies to both you and a spouse as if you were a unit. For example, you may not claim a loss while your spouse re-buys the asset within the 30-day window.

This rule also applies to a corporation that you control. So you cannot have the corporation buy while you’re selling and still claim the loss as a deduction.

2. You sell for a loss but re-buy in a retirement account

You may not sell an asset for a loss in a taxable account and then re-buy the asset inside a retirement account such as a 401(k) or an IRA within the 30-day window and still claim a loss in the taxable account.

Also, it’s important to note that you cannot claim tax losses inside tax-advantaged retirement accounts, so other wash-sale rules do not apply when trading within those accounts.

3. Sell at year-end and re-buy when January starts

Tax-loss harvesting is one of the most popular tax-reduction strategies, but those doing it near the end of the year will want to pay particular attention to this rule. You’ll only have until the end of the calendar year to position your portfolio to be in compliance. So you must clear wash sales by Dec. 31 to be able to claim any associated loss on that year’s tax return.

But don’t think that once the new year begins that you can re-buy the asset within 30 days and not run afoul of the law. Your brokerage is watching, and the delay between the end of the year and when your taxes are due gives your firm plenty of time to report your account accurately.

4. You buy the asset you want to sell less than 30 days before

Some investors may think that they can reverse the order of a wash sale, buying more of the asset before they later sell less than 30 days later and declare a loss on it. But the IRS disallows this activity, since you may not buy 30 days before or after the sale and still claim a loss.

For example, imagine you have 100 shares of stock that you’ve lost money on. Knowing that you want to sell your current position for a loss, you buy another 100 shares. Then less than 30 days later you sell the original 100 shares for a loss. This transaction still counts as a wash sale.

Given their frequent trading of securities, day traders may want to pay particular attention to wash-sale rules, since they’re apt to run into the issue.

Are wash sales illegal and what are the penalties?

It’s worth noting that it’s not illegal to make a wash sale. However, it is illegal to claim a tax write-off for a wash sale. You can create as many wash sales as you want during the course of the year. But you will not be able to claim them as deductible losses for tax purposes until you finally sell your position and do not repurchase the asset for at least the 30-day window.

The IRS will disallow your loss, and you won’t be able to claim a write-off on your tax return. You’ll end up owing taxes on any income that you tried to offset with your wash sale. If you’re not current on your taxes, you can incur typical penalties for non-payment, including fines.

Tax implications of a wash sale

If you have a wash sale, you won’t be allowed to claim the loss on your taxes. Instead, what you need to do is add the loss to your cost basis in the new position. When you sell the new stake, you’ll be able to claim the loss. Let’s run through an example to see how it works.

For example, let’s say you have 100 shares of XYZ stock that you bought for $10 a share, or $1,000 total. You sell the stock for $8 a share and then 23 days later re-buy 100 shares for $7 a share. Because you’ve repurchased the stock within the 30-day window, you have a wash sale.

So you won’t be able to claim a loss on the first lot of 100 shares, and you’ll have to add the disallowed loss onto the cost basis of your new 100 shares. In this case, your initial loss of $200 is added to your new purchase of $700 ($7 * 100 shares), meaning your new cost basis is $900. Your capital gains taxes will be figured using this adjusted cost basis.

Your broker will generally (though not always) figure wash sales for you, so you usually won’t have to do it yourself. But if you’re looking to optimize your tax-loss harvesting, you may want to know exactly where you stand at the end of year so that you can claim all the losses you can.

If you accidentally (or intentionally) write off the loss on a wash sale, the IRS will re-figure your tax and bill you for the difference. Remember, the IRS has all the same figures your broker provides you. So you’ll have to cough up any difference in taxes created by the error.

Bottom line

The wash-sale rule is not hard to avoid running afoul of, but if you’re trading in and out of shares regularly, it may be easy to forget. Rather than add up your losses and gains throughout the year, it may be easiest to simply close out any position you want to claim a loss for and then not repurchase the asset for a full 30 days. Some investors may zero out their balances by the end of November, avoid these assets during December and be ready to trade again first thing in January.