Investing and taxes go hand-in-hand. When you sell a stock for a profit inside a taxable brokerage account, you’ll owe taxes on the realized gain.

But the Internal Revenue Service (IRS) offers tax breaks as well, including the ability for investors to deduct stock losses. These losses, called capital losses, serve to lower your taxable income and reduce your tax bill.

Here’s how to deduct stock losses from your taxes and what to watch out for.

Writing off your losing stock trades: How it works

The IRS allows you to deduct from your taxable income a capital loss, for example, from a stock or other investment that has lost money. Here are the ground rules:

  • An investment loss has to be realized. In other words, you need to have sold your stock to claim a deduction. You can’t simply write off losses because the stock is worth less than when you bought it.
  • You can deduct your loss against capital gains. Any taxable capital gain – an investment gain – realized in that tax year can be offset with a capital loss from that year or one carried forward from a prior year. If your losses exceed your gains, you have a net loss.
  • Your net losses offset ordinary income. No capital gains? Your claimed capital losses will come off your taxable income, reducing your tax bill.
  • Your maximum net capital loss in any tax year is $3,000. The IRS limits your net loss to $3,000 (for individuals and married filing jointly) or $1,500 (for married filing separately).
  • Any unused capital losses are rolled over to future years. If you exceed the $3,000 threshold for a given year, don’t worry. You can claim the loss in future years or use it to offset future gains, and the losses do not expire.
  • You can reduce any amount of taxable capital gains as long as you have gross losses to offset them. For example, if you have a $20,000 loss and a $16,000 gain, you can claim the maximum deduction of $3,000 on this year’s taxes, and the remaining $1,000 loss in a future year. Again, for any year the maximum allowed net loss is $3,000.
  • The last day to realize a loss for the current calendar year is the final trading day of the year. That day might be December 31, but it may be earlier, depending on the calendar.

You can enter any stock gains and losses on Schedule D of your annual tax return, and the worksheet will help you figure out your net gain or loss. You may want to consult with a tax professional if your situation is complicated.

It’s also important to know that short-term losses offset short-term gains first, while long-term losses offset long-term gains first. However, once losses in one category exceed the same type, you can then use them to offset gains in the other category. Short-term gains and losses are for assets held less than one year, while long-term gains and losses are for assets held longer than a year.

Because short-term gains and long-term gains may be taxed at different rates, you’ll need to keep your gains and losses straight as you strategically plan your taxes.

In general, long-term capital gains are treated more favorably than short-term gains. So you may consider taking a loss sooner than you might otherwise, in order to minimize your taxes. Or you might try to use low-tax long-term gains to offset more highly taxed short-term gains.

In fact, many investors strategically plan when and how they’re going to realize their losses to ensure they minimize their taxable income each year, typically by realizing investment losses near the end of the tax year. It’s a process called tax-loss harvesting, and it can save you real money. However, tax-loss harvesting is not restricted to year-end, and it can be a useful practice during the year.

Deducting a loss is valuable only in a taxable account, not tax-advantaged retirement accounts, such as IRAs and 401(k)s, where capital gains aren’t taxed.

It’s easy to find a qualified financial advisor to guide you through life’s most important financial decisions.

Try Bankrate’s free AdvisorMatch service to quickly get connected to a CFP® professional who can help you achieve your financial goals.

How to determine your capital losses

Capital gains and losses are divided between long-term and short-term gains and losses. When you have both long-term and short-term gains and losses in a given tax year, there are ordering rules that need to be used in matching capital gains and capital losses.

  • Long-term capital gains and losses occur after the security has been held for at least one year. Meanwhile, a short-term gain or loss applies to securities that were sold or disposed of after holding for less than a year.
  • Long-term capital gains and losses should be netted against each other as should short-term gains and losses. For example, you might have realized $500 in profit on one long-term holding, while losing $200 on another, which would result in a net $300 long-term gain for the year. Use the same process to calculate your net on short-term gains.
  • Next, the net long-term gain or loss should be netted against the net short-term gain or loss.
  • Whatever is left after this netting process will be taxed accordingly if the net result is either a long- or short-term capital gain, or deductible as described above if a net capital loss.
  • If possible, your tax-loss harvesting efforts should try to avoid a net short-term capital gain as these gains are taxed at your ordinary income tax rate versus the generally preferable long-term capital gains rates. This will help minimize taxes on your investments each year.

Bankrupt companies are an exception to be aware of

If you own a stock where the company has declared bankruptcy and the stock has become worthless, you can generally deduct the full amount of your loss on that stock — up to annual IRS limits with the ability to carry excess losses forward to future years.

The IRS will expect you to have sufficient documentation of your cost basis in the stock to show the amount you lost in this situation. There is no need to actually sell the shares to claim a capital loss.

How much can you save by claiming a stock loss?

So how much does claiming a stock loss save you on your taxes? The answer to that question depends on your tax bracket and whether your loss is offsetting a taxable gain or ordinary income:

  • If you’re offsetting a taxable gain with a loss, then you’re saving the tax on the gains that you would otherwise have paid, and that figure can vary based on whether the gain was long-term or short-term.
  • If you’re claiming a net loss, however, it’s easier to show how much you can save. Federal tax brackets run from 10 percent to 37 percent. So a $3,000 loss on stocks could save you as much as $1,110 at the high end (37 percent * $3,000) or as little as $300 if you’re in the lowest tier.

And if you pay state taxes, then you may be able to save another 4 to 6 percent or more on top of these rates.

This kind of tax savings is why some people ensure that they’re claiming this loss every year.

Limits on the deduction – the wash-sale rule

The IRS does limit your ability to claim a deduction on stock losses, so that you don’t game the system. The IRS will not let you write off what’s called a wash sale. A wash sale occurs when you take a loss on an investment and buy a “substantially identical” investment within 30 days before or after.

If you try to claim a wash sale as a deduction, the IRS will reject your deduction. You won’t ultimately lose the deduction, but you won’t be able to claim it until you stay out of the investment for at least that 30-day period following the loss. When you sell the repurchased stock later, even years later, you can claim the loss.

And don’t try any fancy footwork to try to dodge the rule. You can’t sell the stock and claim the loss, and then have your spouse repurchase the stock within the 30 days. If your partner is buying the stock in that 30-day window, you simply won’t be able to claim the loss.

Selling an investment in a taxable account and then repurchasing the same investment in a retirement account like an IRA within the wash-sale window will also negate your ability to claim the loss.

Some traders may try to buy the stock before they try to claim the loss, but that won’t work either. For example, a trader may have 100 shares of a losing stock that they want to get rid of for a tax write-off. The trader then buys 100 shares of the same stock, and a week later sells 100 shares. That would still be a wash sale since it came within that 30-day window before the sale.

Note that it’s perfectly fine to sell an investment within 30 days and claim a loss. The key element of the wash sale is to repurchase the stock within that 30-day window.

Bottom line

Deducting a stock loss from your tax return can be a savvy move to reduce your taxable income, and some investors take great pains to ensure that they’re getting the most out of this rule each year. However, you might want to be careful that you’re not selling a stock just to get the tax break if you think it’s a good long-term investment. Selling an otherwise good stock at a low point may mean you’re selling just as it’s about to rebound.

Editorial Disclaimer: All investors are advised to conduct their own independent research into investment strategies before making an investment decision. In addition, investors are advised that past investment product performance is no guarantee of future price appreciation.