When you turn a profit on the sale of assets, such as stocks, bonds, mutual funds or real estate, it’s called a capital gain. It’s generally considered taxable income.

In most cases, however, the tax rate on capital gains is lower than the rate on your regular income. In some cases, you might not owe any taxes on your capital gains. The exact capital gains tax rate you’ll pay depends primarily on two things: how long you hold the asset before selling, and your income.

The tax code divides capital gains into two types: long-term and short-term. When you make a profit on the sale of an asset you’ve held for one year or less, that’s defined as a short-term gain. A long-term capital gain comes from a profitable sale of an asset that you’ve held for more than one year.

In this case, tax law rewards patient investors. The tax rate on a long-term gain is lower than what you pay on your ordinary income, such as wages. Short-term gains, on the other hand, are taxed at your ordinary tax rate. (Not sure about your tax rate? Review this rundown on federal tax brackets.)

To ensure your gain is the long-term type, pay close attention to the calendar when selling your assets. The holding period for a long-term capital gain is at least one year and a day. To reach that mark, begin counting on the date after the day you acquired the asset.

For example, if you bought stock on Jan. 10, 2017, and sell on the 10th day of the following January, your one-year ownership of the stock would mean your profit would be taxed at the higher short-term rate.

If you instead sell on Jan. 11, 2018 — 366 days since your purchase, since the day you dispose of the property is part of your holding period — it will net you the lower long-term capital gains tax rate.

Capital gains tax rates, like income tax rates, are progressive. That means higher earners generally pay a higher capital gains tax rate.

When a gain is short-term, it is taxed at the exact same rate as your ordinary income. A long-term gain, however, can be taxed at 15%, 20% or not taxed at all depending on your regular income tax bracket.

The 20% capital gains tax rate applies to taxpayers whose earnings put them in the highest federal income tax bracket (39.6%). You’ll pay a 15% long-term capital gains tax rate if you’re in the next four lower tax brackets: 35%, 33%, 28% and 25%.

And if your income falls into the two lowest tax brackets — 10% and 15% — some or all of your capital gains may not be taxed at all.

The capital gains tax rates described above apply in most scenarios, but there are a few other rates for special investment situations:

Also be aware of the Net Investment Income Tax, or NIIT.

Technically, this is not a capital gains tax, but if your profit on asset sales is substantial, you could find yourself facing this surtax.

The NIIT is an additional 3.8% tax that applies to individuals, estates and trusts with net investment income that exceeds certain thresholds. It was created to help pay for the Affordable Care Act.

The calculations can get tricky, so it’s best to use a tax software program or consult a tax professional if you’re confronted with this tax. But note that the NIIT typically kicks in when an individual taxpayer’s modified adjusted gross income (which is your adjusted gross income with some tax breaks added back) is more than:

Finally, note that increases in the value of assets you still hold do not trigger any capital gains taxes. Capital gains taxes apply only when you have an actual profit from the sale of an asset.

So don’t worry about owing taxes immediately as you watch your portfolio increase in value. Just make sure that when you do cash in some of those holdings, you do so in a way that guarantees the lowest possible capital gains tax rate. You can learn more about current rates in this roundup of capital gains tax rates.

The article Short-Term vs. Long-Term Capital Gains Taxes originally appeared on NerdWallet.