Investing in real estate can be a great path to create wealth while diversifying a portfolio of stocks, bonds, and other securities. But if you're thinking of using your 401(k) or IRA as the vehicle in which you make real estate investments, you need to consider what you gain and what you give up by doing so.

There are lots of ways to invest in real estate. Sometimes holding those investments in a retirement account works out great, but sometimes it's a huge mistake.

Avoid directly buying physical properties

You can use a self-directed IRA or 401(k) to buy physical properties, but it's probably not a good idea. That's because there are a couple of big benefits to investing in rental properties that are somewhat limited when you own them in a retirement account.

For rent sign in front of a house.

Image source: Getty Images.

The first benefit is cash flow. A good real estate investment will produce positive cash flow for you most months. Unless you have a big repair or an extended vacancy, you'll find a steady stream of rent checks coming in that more than offsets your expenses.

You can use that cash flow to invest in more rentals or buy assets like stocks and bonds. You could also use that cash to fund your lifestyle, pay for your necessities, or anything you want. If you invest in a rental property in your retirement account, you'll limit your options for that cash flow. You'll have to reinvest it in something unless you've reached the age at which you can withdraw funds without penalty.

The second benefit is the tax-efficiency of rental properties. You're able to offset your revenue with a lot of expenses. That includes mortgage interest paid and depreciation of the property (even if the value is appreciating in real life). If you use a tax-deferred retirement account, you won't pay any taxes until you go to withdraw funds, but you won't take advantage of some of the tax breaks either. You could therefore end up paying more taxes in the long run as a result.

Other things to consider

In addition, another benefit of investing in physical real estate is that you can move into the property if you want. If you held the property in a 401(k), that would be prohibited. That also means you won't be able to qualify for a lower interest rate offered to people buying a primary residence. Additionally, you won't be able to move into the property for two years prior to its sale to reduce your capital gains tax on the property, if you want to pursue that strategy.

The inability to live in the property held in your 401(k) or IRA also means investment strategies like the live-in flip don't work. Again, the big benefit of that investment strategy is to minimize your tax bill, so you won't be taking full advantage of the retirement account benefits.

Two great ways to invest in real estate in your retirement accounts

That said, there are a couple of ways to get exposure to the real estate market that are more suitable for retirement accounts. That's because they don't come with the tax benefits of directly buying physical real estate and renting it out.

If you're looking for exposure to individual real estate investments, you could write private notes from your self-directed IRA or 401(k) for other investors. For example, someone investing in a rehab project may not be able to get a traditional mortgage for their fixer-upper. You may be able to generate very good returns by offering to lend some of the money in your retirement account to investors you know and trust.

The advantage of doing this in an IRA or 401(k) is that you can defer the income tax on the interest collected on those notes. Unlike investing in a property directly, there aren't any ways to offset the earnings.

Likewise, you can invest in REITs in a 401(k) or IRA. A REIT is required to pay out 90% of its taxable income as a dividend to shareholders. Those profits are passed through to shareholders, so they don't typically get the lower qualified dividend tax rate; investors have to pay their regular income tax rate on them. Holding a REIT in a retirement account allows you to defer the taxes, save more of your money to invest in the near term, and control your tax rate in retirement.

If you want exposure to real estate in your retirement accounts, the best way to do it is by using assets that generate income with no preferential tax treatment. Investing in physical real estate is best suited for outside your retirement accounts, where you can make the most of the tax advantages and cash flow.