Anyone who bought into a high-flying cryptocurrency earlier this year is more than likely tearing their hair out right about now. The major cryptocurrencies, including bitcoin, bitcoin cash, litecoin and ethereum, have crashed to lows not seen in two years. Bitcoin slid below $3,250 this week—a value it last saw in the summer of 2017.

For anyone who's regretting putting their money in the 21st-century version of tulip bulbs, there's a silver lining: At least you can write off the losses on your taxes.

The IRS put out guidance in 2014 letting taxpayers know that cryptocurrencies are considered capital assets by the government, meaning you must pay taxes on the gains. However, the reverse is also true. Taxpayers can write off losses on investments, up to $3,000 for any given year. This includes stocks, bonds, or property, which is how the government views cryptocurrencies.

"Last year, I literally had ten clients running into me at year-end telling me how much money they were making in bitcoin," said Jonathan Medows, managing partner at Medows CPA, a New York accounting firm. A few months later, he said, those clients were coming in to mope.

Get Breaking News Delivered to Your Inbox

There's a few things taxpayers need to do if they're considering cutting their losses. First, those losses need to be realized. That means the de-valued cryptocurrency needs to be sold (not held on to in hopes that it will recover). Exchanging cryptocoins for something else has the same effect. So, if you use bitcoin to buy a car or a cup of coffee, you'll have to account for the difference in value between when you acquired the currency and when you exchanged it.

Loss limits

The IRS only allows taxpayers to deduct $3,000 in capital losses for any given year. Any losses beyond that need to wait until later years.

Here's an example. Dan purchased one bitcoin in early March, for $11,340. By Thanksgiving, after a near-70% plunge in the price of bitcoin, he realized it was a bad investment and unloaded it for $3,804. Dan has a loss of over $7,500; he'll be able to deduct $3,000 from his income for this year, another $3,000 for 2019, and $1,500 in 2020, outside of whatever other investment losses he might have.

When exactly someone bought bitcoin makes a big difference, tax experts note.

"The people who are suffering right now are people who were buying at the end of last year, when Bitcoin was shooting up past five thousand, seven thousand, fifteen thousand," said Victor Jaramillo, a tax attorney at Caplin and Drysdale. "If you invested two years ago, you're still in the green."

Getting out

Given crypto's general trajectory, though, even those who haven't lost money might be thinking of selling their holdings. Those hoping to minimize their tax liability can offset those gains by selling other assets that have dropped in value. It's also possible to donate bitcoin, just as one might donate appreciated stock—but, said Jaramillo, your recipient would need to be technically able to accept the donation.