Man walking by NYSE
Eduardo Munoz Alvarez/Getty Images

The stock market has been in overdrive for years, which means you could be making a bundle on your investments.

But with the exception of savings in retirement accounts like 401(k)s and IRAs, the tax man will probably take a cut of your newfound wealth. It’s called capital gains, and how much tax you pay depends on how long you hold the investments, and how much you earn.

Long-term vs. short-term capital gains taxes

Long-term capital gains are those you earn on assets you’ve held for more than a year. Under the new 2018 tax law, such gains are taxed at three rates, depending on your overall income: zero, 15 percent and 20 percent. For example, a married couple filing jointly pays no capital gains tax if their total taxable income is $77,220 or less. They’ll pay 15 percent on capital gains if their income is $77,221 to $479,000. For couples above that income level, the rate is 20 percent. There also is a de facto fourth bracket for certain high earners who must pay an additional 3.8 percent on investment income as part of the Affordable Care Act.

By contrast, short-term capital gains are from assets you buy and sell within one year. They are taxed as regular income, which is always higher than the long-term capital gains rate. The government gives you a break on long-term gains to encourage buy-and-hold investments (as opposed to speculating), which stabilize the economy.

How capital gains taxes work

Let’s say you buy $1,000 worth of stock in January, and sell it in June for $1,200. You’ve made short-term capital gains of $200. You and your spouse have taxable income of $85,000 (including your stock gain), which puts you in the 24 percent income tax bracket. So you’ll give $48 of that $200 gain to Uncle Sam, leaving you with $160.

Looking for a less-risky investment? Consider a long-term certificate of deposit with a high interest rate.

Consider instead that you hold on to your stock until the following January, at which point it’s earned $400. Now it’s a long-term capital gain—and your family income puts you in the 15 percent bracket for that gain. Now you’ll pay $60 in tax, realizing a $340 profit. In other words, by doubling the length of your investment you have more than doubled your actual profit, by taking advantage of the favorable tax rate for long-term capital gains.

What counts as a capital gain?

Capital gains are basically any profits resulting from the sale of assets. That includes the sale of tangible assets like artwork, a car, or a boat—assuming you sell for more than you paid. (Most of the stuff you own, including normal cars, will depreciate in value over time, so capital gains tax rarely applies to possessions.) It also includes the sale of real estate, with some big exemptions for your principal residence.

Note that stock dividends also count as capital gains. If you have a lot of dividend gains (outside of retirement accounts), a financial planner can help reinvest those gains in ways to mitigate the tax bill. Many so-called robo-investment programs will do it automatically.

What if I lose money on investments?

Fortunately the tax on capital gains—both long-term and short-term—is applied to your net investment income. That means the IRS looks at the total of your gain (or loss) when calculating tax.