If you’re confused about how stocks and other investments are taxed, you’re not alone.

When you sell investments at a profit, you’re subject to capital gains taxes. But capital gains tax rates vary based on the length of time you held the asset. And that can get a little murky.

If you’ve owned the asset for one year or longer, you’ll have to pay long-term capital gains taxes. But if you’ve owned it for less than one year, the taxes you’ll pay will be short-term capital gains taxes, and the rate will usually be higher.

We break down the difference between short-term and long-term capital gains tax rates, what the exceptions are and what you can do to lower your tax liability.

What is the short-term vs. long-term capital gains rate?

Generally, long-term capital gains tax rates are lower than short-term rates. The long-term rates are 0 percent, 15 percent or 20 percent, depending on your tax bracket. Individuals who make less than $39,375 and married couples who earn less than $78,750 pay no taxes on long-term capital gains. Individuals who earn $39,376 to $434,550 (and married couples earning $78,751 to $488,850) pay 15 percent in long-term capital gains taxes. And taxpayers earning more than that are required to pay 20 percent of their long-term capital gains in taxes.

If you’ve owned an investment asset for less than one year when you sell it, you’ll be required to pay short-term capital gains taxes, which are taxed the same as your regular tax rate.

What triggers the capital gains tax?

The sale of a taxable investment is what triggers the capital gains tax. If you have investments that are earning income, but you haven’t cashed in, you haven’t realized the gain—and you don’t have to pay capital gains tax until you do.

If you own shares in a mutual fund, for instance, and the value of your shares grows every year, you don’t owe any taxes on that growth until you sell it and take the income from it. Similarly, if you own a piece of vacant land that rises in value each year, you will have to pay property taxes each year, but you don’t have to pay capital gains taxes on it until you sell it.

When you sell an investment for profit, your capital gains taxes are due in the tax year that the investment was sold. So if you sell a stock at a gain in 2019, your related capital gains taxes are due when you file your 2019 tax return in early 2020.

How is my capital gains tax calculated?

The amount that is taxed is not the sales amount. Instead, you are taxed on the amount you earned on the investment. That means the amount you paid originally for the investment and any fees you paid while you held it, such as account management fees, are not taxable.

To calculate your taxable capital gain, you must know your cost basis or the amount you paid for it originally. If you didn’t record this information, you should be able to find it on a statement or a confirmation of your order to purchase. Then find the sales amount on your order execution statement or your brokerage account statement. Subtract the sales amount from your cost basis. This is the capital gain (or if it’s a negative number, it’s a capital loss).

Are there exceptions?

Yes, there are a few exceptions that can change your capital gains tax liability. For instance, if you’ve sold a collectible asset at a profit, such as coins, precious metals, antiques or fine art, your long-term capital gains tax rate will be higher than the standard rate. Capital gains on collectibles are taxed at 28 percent.

Also, if you’re a high-earning investor, you may owe an additional net investment income tax on top of your capital gains taxes. This is an extra 3.8 percent that is applied to whichever is smaller—your net investment income or the amount by which your modified adjusted gross income exceeds $200,000 for individuals or $250,000 for married couples.

Can I do anything to lower my capital gains tax?

There are several things you can do to decrease your capital gains tax liability. The first is to leverage the long-term capital gains tax. Remember that capital gains taxes on short-term investments are higher than on long-term investments. So if you hold your investments for a year or longer, you’ll qualify for the lower long-term capital gains tax rate.

Also, you can balance losses against gains to lower your taxes. For instance, if you sell one investment at a gain of $5,000 and another at a loss of $3,000, you’ll only be liable for paying capital gains taxes on $2,000.

If you invest through tax-advantaged accounts, you can also save on capital gains taxes. Accounts like 401(k) plans, IRAs and 529 college savings accounts allow investments to grow tax-free or tax deferred, so if you sell investments within those accounts, you don’t have to pay capital gains tax. With traditional IRAs and 401(k) plans, you’ll have to pay taxes when you make withdrawals in retirement, but with Roth IRAs and 529 plans, you never pay taxes on investment earnings.

The capital gains tax rates reinforce the idea that the best way to invest in the market is with a long-term view. Rather than selling investments quickly when the market dips, riding out the ups and downs will historically yield stronger returns. And as a bonus, holding on to investments for a longer period of time means you’ll also pay less in capital gains taxes.

This article contains the current opinions of the author, but not necessarily those of Acorns. Such opinions are subject to change without notice. This article has been distributed for educational purposes only and should not be considered as investment advice or a recommendation of any particular security, strategy or investment product. Information contained herein has been obtained from sources believed to be reliable, but not guaranteed. Acorns does not provide legal or tax advice. Please consult your tax and/or legal counsel for specific tax or legal questions and concerns.