Investors love to pick winning investments, but you'll inevitably find some losers in your portfolio as well. When you sell your investments, you'll recognize gains or losses for income tax purposes, and you'll have to break out those capital gains against capital losses by their holding period if you want to account for them correctly for tax purposes. In general, you can use losses to offset gains, and then take up to an annual limit of \$3,000 of additional losses as a deduction against other types of income. This gain and loss calculator can get you started, but you'll also need to know more tax rules to finish the job. Let's look more closely at how gains and losses work and how the calculator can help you get off on the right foot.

* Calculator is for estimation purposes only, and is not financial planning or advice. As with any tool, it is only as accurate as the assumptions it makes and the data it has, and should not be relied on as a substitute for a financial advisor or a tax professional.

## How gains and losses work

When you sell a stock, whether you have a capital gain or loss depends on what you paid for it and what you got when you sold it. If you paid more than you received, you'll have a loss; otherwise, you'll have a gain. You also have to pay attention to the holding period, because tax treatment differs depending on how long you've owned a stock. Sell after a year or less, and you'll have short-term capital gain or loss. Hold onto the stock for more than a year before selling, and you'll have long-term capital gain or loss. Within each holding period category, you'll want to figure the total gains and losses, and then offset them to get either a net gain or a net loss.

Image source: Getty Images.

The calculator helps you do that. For instance, say you have a \$1,500 short-term gain, a \$1,000 short-term loss, a \$500 long-term gain, and a \$2,000 long-term loss. Run those numbers through the calculator, and you'll get a net short-term gain of \$500 and a net long-term loss of \$1,500. That's where the calculator stops, but there's more to the story.

## Reconciling short-term and long-term gains and losses

Once you've figured out the net gain or loss in each holding period category, you must use the losses in one category to offset the gains in the other. In this situation, you'd take \$500 of the long-term loss to cancel out the short-term gain. That leaves you with \$1,000 of long-term losses remaining.

After that, you can take any remaining loss from either category and use it to offset other types of income. For instance, if you have investment income or earnings from a job, you could take the \$1,000 of long-term losses remaining and reduce your taxable income by that amount.

If you have a terrible year and your losses exceed \$3,000, then you won't be able to claim all of your losses against income in the current year. However, any amount you've lost beyond the \$3,000 that you're able to use this year can be carried forward to future years. It might take time for you to use up a major loss, but there's no time limit for the number of years you can carry forward those losses into the future.

## One caveat for taking losses

Finally, if you sell a stock at a loss, be sure that you know the rules that govern recognizing that loss for tax purposes. Specifically, the tax laws don't allow you to buy back the same stock you sold at a loss within 30 days of the sale. If you do so, then your capital loss will be disallowed. This is known as the wash sale rule, and it only applies to losses. You can sell a stock at a gain and buy it back immediately, and the IRS will be happy to collect taxes on the gain.

Selling your investments is something even long-term investors have to deal with, and the tax consequences can be sizable. By knowing how to weigh gains and losses against each other, you'll be in a better position to predict how much tax your investment sales might cost you in the end.