Your goal in investing should be to grow your wealth, and holding onto stocks for a long time is generally the best way to do that. But still, you may find yourself wanting to sell a stock at a profit in the near term, whether because you need money or you feel you have a key opportunity to cash in at a high.

But just as the IRS is able to collect taxes on your regular earnings, so too is it entitled to a piece of your profits when you sell stocks for more than what you paid for them. It's a concept known as capital gains taxes, and unless you're housing your investments in a retirement savings plan like an IRA or 401(k), you'll be liable for those taxes year after year.

But not all capital gains taxes are created equal, and if you're going to sell an investment at a profit, here's one important rule to try to follow: Make sure you hold that stock for at least a year and a day before selling it off. Doing so could make a huge difference as far as your tax bill is concerned.

Smiling man at laptop raising arms in triumph

Image source: Getty Images.

Long-term versus short-term gains: Know the difference

There are two types of capital gains tax you'll be subject to: long-term gains and short-term gains.

Long-term capital gains apply to investments you've held for at least a year and a day, whereas short-term capital gains apply to those you've held for a year or less. Long-term capital gains have a much more favorable tax rate than short-term gains, so in some cases, retaining an investment for just a few more days or weeks could have a huge impact on your finances.

Short-term capital gains are taxed at your ordinary income tax rate. For example, if you're a higher earner and fall into the 32% bracket on your highest dollars of earnings, you'll be taxed at that rate for short-term gains in your portfolio.

Long-term capital gains, on the other hand, are taxed at a lower rate. If you're single earning up to $40,000, your tax rate on long-term gains will actually be 0%. If you earn between $40,000 and $441,450, you'll enjoy a 15% long-term capital gains tax rate. And if your income exceeds $441,450, your long-term capital gains tax rate will top out at 20%. By contrast, if you're single earning over $207,350, your marginal tax bracket is 35% or higher, so clearly, you'll save a lot by being taxed at the long-term capital gains rate over the short-term gains rate.

The same holds true if you're a married couple filing jointly. You'll pay 0% on long-term capital gains with earnings of up to $80,000, while earnings between $80,000 and $496,600 mean you'll be limited to a 15% tax rate. And as is the case for single tax filers, the maximum tax rate you'll pay on long-term gains is 20%, and that's if your earnings are above $496,600.

Sometimes, it pays to wait

As an investor, you may not always be in a position to hold stocks for a year and a day or longer before selling them, but knowing how capital gains taxes work could help you make smarter decisions with your portfolio. No matter how much money you make from the sale of a stock, your goal should be to keep as much as possible for yourself, and avoiding short-term capital gains is a good way to make that happen.