This article was updated on January 6, 2017. It was originally published on December 14, 2015.

Click here to learn more about long-term capital gains tax rates in 2017.

Long-term capital gains are taxed at a lower rate than you might expect. While short-term gains are taxed at the same percentage rate as your U.S. federal income tax bracket, long-term gains get a haircut of no more than 20%, and usually just 15%. In fact, in some circumstances, you may pay nothing at all in taxes on your long-term gains.

"Capital gains" license plate

Image source: Flickr user Global X.

Defining terms

Let's start with some definitions. Long-term capital gains stem from assets you've held for more than a year -- that's 366 days or longer. Short-term capital gains are from assets held for a year or less.

For most of us in 2016 (and until further notice), the tax rate on long-term capital gains is 15%, while those in the top bracket pay 20% and those in the 10% or 15% tax brackets pay 0%. Those earning more than $200,000 for single filers and more than $250,000 for joint filers may also have to pay a 3.8% "Net Investment Income Tax." Overall, that's rather low, historically speaking. Between the 1950s and the late 1970s, for example, the rates rose from about 20% to nearly 40%, and for a short period in the late 1980s, they were the same as the taxpayer's income tax rates, which could top 30%.

For short-term gains, the capital gains tax rate is your ordinary income tax rate, which could be in the 33% to 40% range if you're a high earner. (For most of us, it will be 25% or maybe 28%.)

If paying even 15% on your long-term capital gains seems unpleasant, buck up -- because you don't always have to pay it.

The Roth exception

If your long-term capital gains occurred within a Roth IRA -- for example, you bought a stock in your Roth, held on for years, and then sold the shares within the Roth, realizing a gain -- you can end up paying no taxes at all on the gain. You'll have to follow the Roth rules, of course, such as not withdrawing proceeds until you're at least age 59-1/2 and have had the account for more than five years. But those following the rules with a Roth IRA get to enjoy its raison d'etre -- tax-free growth and withdrawals. (Withdrawals from traditional IRAs are taxed at ordinary income tax rates. Roth 401(k)s, meanwhile, a relatively new option at many workplaces, offer tax-free withdrawals like Roth IRAs.)

Wipe out the tax with losses

Another way to avoid paying long-term capital gains taxes is to offset your gains with losses. If you have $6,000 in long-term capital gains and $2,000 in capital losses, you can subtract that $2,000 and only be taxed on $4,000, saving $500 if you're in the 25% tax bracket.

If you have more losses than gains, you can wipe out all your gains and then use up to $3,000 of losses to offset your overall taxable income. If you still have more losses, they can be carried forward into future years to reduce future taxes.

Hang on for big bucks

Even if you're paying 15% on your gains, though, that's not the end of the world. You still keep 85% of the gains, after all. Having gains means you've been investing effectively, ideally accumulating critical retirement assets or achieving other financial goals. If you're among those who face a 20% tax rate, that's likely because you're already on solid financial ground, with a hefty income.

With your investments, remember that hanging on to stock in healthy, growing companies over many years is a great way to build great wealth. A short-term focus can be counter-productive, generating higher tax rates and commission costs. Long-term investing is a smart strategy and offers lower long-term capital gains tax rates, as well.