Sell an investment at a loss and you can use that loss to offset capital gains from your winners. Up to $3,000 in excess losses can also offset ordinary income each year, and the rest carries forward. Just don’t rebuy the same investment within 30 days, or the wash sale rule voids the loss.

Source