Capital gains taxes are the taxes you owe when you make income on a taxable investment or asset. That income could come from the sale of stocks, bonds, mutual funds, real estate (but not usually from the sale of your personal residence), or other types of investments.

When you sell an investment asset for profit, part of that income must go to Uncle Sam, just like when you earn your regular paycheck. But investment income—known as “capital gain”—is taxed differently from your regular paycheck.

The amount of tax you owe on a capital gain depends on the price at which you sold the investment, the amount you originally paid for the investment, and how long you owned the investment before you sold it.

When do I have to pay capital gains taxes?

You don’t have to pay taxes on capital gains until the gain is realized. That means you won’t owe taxes on a stock, mutual fund or other investment until you sell it and actually reap the gain. If you own shares in a 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 at a gain, the 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 do I calculate my capital gain?

When you sell a stock or other asset, you don’t have to pay taxes on the entire sales amount. Instead, you just have to pay capital gains tax on the amount you earned on the investment. That means the amount you paid for it originally 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 the investment 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).

If you want to refine the number even more, you can subtract the brokerage commissions you paid related to the purchase and sale of the investment.

So, how much do I have to pay?

The amount you pay in capital gains taxes will depend on your tax bracket, which is determined by all the other information that is included in your tax return. If you’ve held the investment for more than one year, you’ll owe long-term capital gains taxes.

Long-term capital gains tax rates are generally lower than short-term rates. The long-term rates are 0 percent, 15 percent or 20 percent, depending on the tax bracket you fit into. 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.

There are a few exceptions. The long-term capital gains on collectible assets, such as coins, precious metals, antiques or fine art are taxed at a higher 28 percent.

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 the same as your regular tax rate.

High-earning investors may owe an additional net investment income tax on top of their 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 reduce my capital gains tax liability?

Yes, you can pair capital losses with capital gains to lower or neutralize your capital gains tax liabilities. You experience a capital loss when you sell a taxable asset for less than your original purchase price.

If you have some capital gains and some capital losses, the difference between the two is your net capital gain. And you only have to pay capital gains tax on the net gain. For instance, if you sold one stock at a gain of $2,000 this year, and you sold another stock at a loss of $1,500, you would only be responsible for paying taxes on the remaining $500. (If the scenario was switched and you ended up with a net capital loss, you’d be able to deduct that net loss from your taxable income.)

Earning income is what investing is all about. But when you’re ready to cash out on that investment, keep in mind that you will have to pay capital gains taxes on your earnings. Now that you understand capital gains taxes, how they are calculated, and how they can be reduced, you’ll be better prepared to make informed decisions.

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.