Any time you make money, whether it's through your job or another source, the IRS is bound to want its share. You're required to pay a capital gains tax whenever you sell an investment at a profit. Capital gains taxes also apply to the sale of a home, though proceeds from a primary residence are exempt from capital gains up to a certain amount. Knowing how to reduce your capital gains tax can help you retain more of your money, so use the following tips to minimize your tax burden going forward.

Calculating capital gains for tax purposes

IMAGE SOURCE: GETTY IMAGES.

1. Invest with a tax-advantaged retirement account

When you invest using a traditional brokerage account, you're required to pay capital gains taxes any time you sell an investment at a profit. Specifically, you'll owe the IRS a portion of your gain during the same tax year you realize that gain. If, for example, you sell shares of stock in February 2017 and realize a gain of $3,000, you'll need to pay capital gains taxes on that amount when you file your 2017 return.

Retirement accounts like IRAs and 401(k)s work differently. When you invest with an IRA or 401(k), your money gets to grow on a tax-deferred basis, which means you won't pay capital gains taxes along the way. The only time you'll pay taxes with a traditional IRA or 401(k) is when you take withdrawals in retirement. Roth IRAs offer an even better benefit -- you won't pay capital gains taxes year after year, and your withdrawals will be tax-free in retirement.

2. Hold your investments longer

The amount of time you hold an investment can impact the amount of tax you'll pay on it. Investments held for one year or less are subject to a short-term capital gains tax, which is currently the same rate as your ordinary income tax rate. But long-term capital gains, which apply to investments held for at least a year and a day, are subject to a more favorable tax rate than short-term gains.

Your long-term capital gains rate will depend on the tax bracket you fall into, as follows:

Tax Bracket

Long-Term Capital Gains Tax Rate

10%

0%

15%

0%

25%

15%

28%

15%

33%

15%

35%

15%

39.6%

20%

DATA SOURCE: IRS.

One thing to note is that although these numbers are currently applicable, President Trump has suggested a trimmed down version of the above system that could change things up a bit if his plan goes through. But no matter what, holding investments for at least a year and a day will reduce the amount of capital gains tax you're required to pay on them.

3. Sell losses to offset gains

Not every investment is a winner, so if you have poorly performing assets in your portfolio, it might pay to cash out those losses. The reason is that capital losses can be used to offset capital gains. If, for instance, you sell a stock at a $5,000 gain but also take a $5,000 loss that same tax year, you'll cancel out your gain and avoid paying taxes on it. Not only that, but if your net investment losses for the year exceed your gains, you can use up to $3,000 to offset ordinary income.

4. Record all home improvements you make

Most people who sell their homes aren't required to pay capital gains taxes. That's because you're allowed to exempt up to $250,000 in capital gains from a home sale as a single tax filer, and up to $500,000 as a joint tax filer, provided you've owned and lived in that home for at least two of the five years preceding the sale. However, if property values have climbed in your neighborhood and you're looking at a high enough gain to be subject to taxes, you can use home improvement costs to help offset your capital gains.

This is why it's important to retain records of any improvements you make while you're living in your home. These might include installing a fence or swimming pool, upgrading a furnace, or finishing a basement. Any improvements that add to the value of your home can get added to the cost basis of your property, thus lowering the amount of your gain and the taxes that go with it.

Let's say you file a joint return and you're looking to sell your home, which you bought for $300,000, at a price of $850,000. Normally you'd face some capital gains taxes, but if you have receipts documenting $50,000 in home improvements, you'll get to add that $50,000 to your cost basis, thus knocking your gain down to $500,000, all of which you can exempt. Just remember that this provision applies to home improvements only, not repairs. If you spend $2,000 to fix your roof, you can't add that amount to your home's cost basis.

Avoiding capital gains taxes is often a matter of employing the right strategy. And the more money you're able to shave off your tax bill, the more you'll get to keep for yourself.

The Motley Fool has a disclosure policy.