You know that “nothing is certain except death and taxes,” as Benjamin Franklin once said.

This is true whether you have earned income from a job, or whether your income is the result of financial investments.

The good news is that investment income can be more efficient than earned income in some cases — if you plan ahead and you are careful about building a tax-efficient portfolio.

Long-Term Capital Gains

Many people invest with the idea that some day their portfolios will grow. They can sell investments for more than they paid, and the difference can provide a comfortable income.

If this is your approach, one of the best options is to use long-term capital gains. Stock trading frequently, and harvesting profits on short-term gains isn’t very efficient. If you have held an investment for less than a year, you will have to pay income taxes on the gain at your regular rate.

On the other hand, if you keep the investment for more than a year, it’s considered a long-term asset, and the current highest rate you will pay is 20% — and that’s only if you make $400,000 a year as a single filer, or $450,000 as a joint filer. At other income levels, your long-term capital gains tax is either 0% or 15%. If you are in the 10% or 15% tax bracket, you won’t pay taxes at all on your long-term capital gains. Keep this in mind as you build your portfolio.

Tax-Advantaged Accounts

One of the best ways to build a tax-efficient portfolio is to make use of tax-advantaged retirement accounts. You can grow your money in a tax-deferred account, like a Traditional IRA or a Traditional 401(k). More of your money goes in right now, and you don’t pay taxes on it until you withdraw it. If you think that your tax rate will be lower during retirement, a tax-deferred account can help you avoid paying taxes now, and pay less later.

A Roth account does a little better. If you qualify for a Roth IRA or a Roth 401(k), you pay taxes now, but your money grows tax-free. This means that when it comes time to withdraw, you won’t pay taxes. If you think that taxes will go up between now and your retirement, a Roth can be a good choice.

Roth accounts are also popular for many normally tax-inefficient assets. Stocks can be held in these accounts and improve their efficiency. Many investors like to keep US Treasuries and dividend stocks in Roth accounts, since you don’t have to pay taxes on the income. The dividends earned on stocks held in a Roth account aren’t federally taxed later, and you can reinvest them and receive an even greater benefit.

Another option is to use a Health Savings Account if you qualify. Not only do you receive a tax deduction for your contribution, but the money grows tax-free as long as you use it for qualified health care expenses. You can hold a variety of investments in your HSA, and reap the benefits of tax-free growth as you build up an account for medical costs. Once you reach age 59 ½. the HSA operates as a Traditional IRA if you decide to withdraw for non-medical expenses.

Finally, realize that some assets are already tax-efficient on a federal level. Interest on municipal bonds is not taxed by the federal government, so it’s a waste to hold them in tax-advantaged account. Instead, maximize your contribution dollars by adding less efficient assets to your tax-advantaged accounts.