No investor likes losing money. But when the value of your investments drop, there could be an upside realizing losses before the year’s end can help you reduce your tax bill.

By using a strategy known as tax-loss harvesting, investors can sell stocks, bonds, mutual funds or other investments that have lost value and reduce their federal taxes on short- or long-term capital gains on investments that fared better. Investors with more capital losses than gains can use up to $3,000 a year to offset ordinary income and even carry over the remainder to future years.

“Tax-loss harvesting is a great opportunity to reduce taxable income and should be a part of year-end tax planning,” says Jason Speciner, certified financial planner at Financial Planning Fort Collins. “Investors can use capital losses to offset or eliminate capital gains dollar for dollar in unlimited amounts.”

Some robo-advisors have developed algorithms to automatically search for such opportunities, but investors should also do their own assessment of how tax-loss harvesting might fit into their overall investment picture.

Here’s how to make the most of your losses before the end of the year.

Pick your losses

In deciding which investments are the best candidates for tax-loss selling, don’t cherry-pick the biggest losses. The investments should be holdings that no longer fit with your investment strategy and can be replaced by other investments to play a similar role in the portfolio.

“The tax tail should never wag the dog,” says Justin Porter, certified financial planner with Porter Wealth Management. “You should rebalance and take losses because it makes your portfolio better, not just for tax reasons.”

Gains and losses can be short-term (investments held for a year or less) or long-term (held for longer than a year). Short-term gains are taxed at the marginal tax rate on ordinary income, which can be as high as 37%, while long-term gains are taxed at the capital-gains tax rate, which can be significantly lower.

When offsetting losses, gains of each type are first netted against the same type — short-term losses against short-term gains, and long-term losses against long-term gains. Then the balances of those sums net out each other.

“From a tax perspective, ideally you want to have short-term or long-term losses to take against short-term gains,” says Ryan Firth, a certified public accountant at Mercer Street. “It’s not as beneficial from a tax perspective to net long-term gains against short-term losses.”

Capital losses are deductible up to $3,000 per year and any remaining losses can be carried forward into future tax years.

Time it right

For those with a globally diversified portfolio with historical gains, this year may be a good time to harvest losses, particularly those in fixed income and international stocks, says Vid Ponnapalli, a certified financial planner at Unique Financial Advisors & Tax Consultants.

He says a client who stuck with an old mutual fund in her taxable account in order to avoid realizing the capital gains, is now considering rebalancing the portfolio by selling the mutual fund and then offsetting that gain with the losses in her bond and global positions. “She could recognize a total loss of $3,000 for the year so she gets a tax break on this.”

A different client Ponnapalli works with has seen significant short-term gains in big-name tech stocks. “We are considering offsetting their short-term gains again with losses in their bond and international positions.”

Another move to consider: taking your losses at a time when you expect mutual fund distributions.

“If you have mutual funds in a taxable account, it is important to check the estimated mutual fund distributions that the fund families release ahead of time,” says Chris Jackson, certified financial planner with Lionshare Partners. “By tax-loss harvesting this fund, not only do you avoid the capital gains distribution, you also capture a tax deduction. The combination could be a substantial savings.”

Maintain diversity, but avoid a ‘wash sale’

If you could sell a security that’s lost money to claim the tax loss and immediately buy it back again to avoid getting whipsawed by price changes, that would be great, right?

“Sounds like a good idea, but that’s called a ‘wash sale’ and isn’t allowed,” says Bradley Nelson, a financial planner with Lyon Park Advisors.

But what you are allowed to do is sell one mutual fund or ETF and immediately buy one that is not “substantially identical,” according to the SEC, says Nelson.

“The only tax-loss harvesting strategy we recommend is selling a fund or ETF in a specific category and immediately buying another similar but not identical fund or ETF in the same category,” says Nelson.