Saving a portion of your salary in a 401(k) is one of the best ways to set yourself up for a happy retirement. But 401(k)s aren't the only game in town when it comes to retirement planning. And one account in particular offers a whole host of advantages over a 401(k) for those eligible.

A health savings account (HSA) is designed to offer tax savings on medical expenses. But you can take advantage of all those tax savings and turn it into an incredible retirement account.

What's an HSA?

An HSA is a special account available to members of certain high-deductible health insurance plans. The idea is that since you have a high deductible, the government wants to make it easier for you to afford your medical care, thus providing tax advantages for eligible expenses. You can contribute funds to your HSA, and you won't have to pay any taxes on qualified medical expenses when they come up.

Unlike a flexible spending account, HSA funds never expire. Once they're in the account, they're yours to use whenever. Whether that's next month or next decade, it doesn't matter.

If you're offered an HSA through your employer, you can elect to make a salary deferral to the account, and your employer may also contribute to your HSA. These contributions are exempt from payroll taxes as well as income tax. You can also contribute directly to an HSA, but it'll be with funds you paid payroll taxes on.

Unlike a 401(k), you can access HSA funds immediately. If you use the funds for a qualified medical expense, you won't pay any taxes on the withdrawal. Otherwise, you'll pay income tax. If you're younger than age 65, you'll also owe a 20% penalty on a non-qualified withdrawal.

How to make the most of it

You can make the most of an HSA by using it as an investment account. Several providers allow you to invest in a wide variety of funds and other securities. 

Unlike a 401(k), you're not limited to the provider supported by your employer. If your employer sets up an account with a more limited provider, you have the right to move your funds whenever and to wherever you'd like. 

If you can afford to pay for your medical expenses with funds outside of your HSA, do so and hold on to the receipts. Archive them somewhere you'll be able to access many years from now. When you're ready to start withdrawing funds from your HSA to fund your retirement, you can submit your receipts and make a withdrawal.

Ultimately, this strategy provides superior tax advantages to a 401(k). First, contributions made through payroll deductions are exempt from payroll taxes. They're also exempt from income tax. The growth in your investments is also tax protected, so you won't pay any capital gains taxes. And if you only have qualified distributions (because you saved your receipts), you won't pay any income tax on the withdrawals either. A 401(k) can usually get you only two out of four of those tax advantages.

When you are past age 65, you can start taking distributions for non-qualified expenses and only pay income tax. In that case, the HSA effectively functions as a traditional IRA. That's not recommended, though, as you'll likely have plenty of medical expenses you can use your HSA for later in life. Tap your other retirement savings first before going down this path.

The downside of the HSA is the contribution limits are far lower than a 401(k). For 2022, the limits are $3,650 per year for an individual and $7,300 for a family. That includes any employer contribution. For comparison, employees can contribute up to $20,500 to a 401(k), and that's on top of employer contributions.

But if you're eligible for an HSA and in a strong financial situation, it likely makes sense for you to maximize your contribution, invest it, and use it as a retirement account.