Health savings accounts, or HSAs, aren't available to everyone. But for those enrolled in a high-deductible health insurance plan, they're worth taking advantage of.

HSAs allow you to set aside money for both near-term and far-off medical expenses. Because those funds don't expire, you can carry that money all the way into retirement if you so choose and take withdrawals then, when your healthcare expenses are likely to be more substantial.

In fact, there's a benefit to waiting to tap your HSA. Any funds you don't withdraw immediately can be invested and grown into a larger sum.

A person at a laptop taking notes.

Image source: Getty Images.

HSAs offer the benefit of being triple tax-advantaged. Contributions are tax-free, investment gains are tax-free, and withdrawals are tax-free when used for qualified medical expenses.

Now because HSAs are loaded with tax breaks, they impose steep penalties for non-medical withdrawals. But once you turn 65, you can remove funds from an HSA and use them for any purpose without being penalized. In that scenario, all that happens is that you pay taxes on the sum you withdraw.

It's for this reason that HSAs are often touted as a retirement savings plan of sorts. But should you save in an HSA at the expense of your IRA or 401(k)?

Don't limit your options

While it's true that HSAs actually offer more tax benefits than IRAs and 401(k)s when used for medical purposes, they're not meant as a substitute for an IRA or 401(k). Both IRAs and 401(k) plans allow you to start taking withdrawals beginning at age 59 1/2. And to be clear, the only stipulation with these plans is that you wait that long to touch your money. Once you turn 59 1/2, those funds are yours to use for any reason.

With an HSA, penalties for non-medical withdrawals will apply until age 65. But you may want to retire earlier. Or, you may have to retire earlier. A lot of people are forced out of a job prematurely by layoffs or health issues. And so while it's a good idea to fund an HSA, you shouldn't neglect your IRA or 401(k) in the process, because you need access to a retirement plan that gives you the option to take penalty-free withdrawals at an earlier age.

Furthermore, many employers that sponsor 401(k)s offer free matching dollars. And if you're privy to that arrangement, it makes sense to capitalize on it. As such, you shouldn't put money into your HSA before snagging your full 401(k) match.

Now IRAs don't offer matching incentives like 401(k)s. But you should still make an effort to fund an IRA as well as an HSA because ultimately, IRAs are more flexible.

Manage your accounts wisely

While having money in an HSA can come in very handy during retirement, and HSAs offer a host of tax breaks, you shouldn't push your IRA or 401(k) savings efforts aside in favor of solely focusing on funding an HSA. But you shouldn't neglect your HSA, either. These plans can work well together to provide the financial security you need in retirement -- especially since healthcare could end up being your single largest expense when you're older.