Health savings accounts (HSAs) have a benefit their creators may not have envisioned: they can double as retirement savings accounts.

Since 2003, individuals and families who have health insurance policies with high deductibles, and aren’t eligible for Medicare, have been allowed to contribute pre-tax dollars to HSAs. The IRS defines high deductibles as $1,300 for individuals and $2,600 for families in 2016.

If you meet one of those thresholds, you can put $3,350 (individual) or $6,750 (family) into an HSA this year. If you’re 55 or older, you can kick in another $1,000 in catch-up contributions. You can leave the money in cash, or you can invest it in the money market, mutual funds or stocks. You can withdraw some or all of those funds, tax-free, from your HSA to pay for qualified medical expenses as defined by the IRS.

Any money left in your account at year’s end stays there, and you can use it in future years. Here’s the bonus: when you turn 65, your HSA funds are no longer limited to qualified medical expenses. You can spend them however you want, although HSA money spent on anything other than qualified medical expenses will be subject to taxation.

The list of qualified medical expenses is pretty expansive, although it doesn’t include premiums, deductibles or co-pays. It does include services that some insurance policies don’t cover, such as birth control, lab fees, psychiatric care, eyeglasses and contact lenses, drug and alcohol rehab.

You should consult the list before using HSA funds to pay for medical care. Make a mistake and the IRS will sting you with a 20% penalty.

Contributing to an HSA can lower your taxable income and might even move you into a lower tax bracket. That’s because the money you put in your HSA comes out of your paycheck before taxes are applied.

Another benefit that HSAs offer is that you can “shoebox” your withdrawals. That is, you can document your qualified medical expenses in one year, pay for them out of pocket, then withdraw the amount you paid at a later date, tax-free.

The Bottom Line

 Don’t confuse HSAs with flexible spending accounts. They’re different. An FSA is similar to a 401(k) in that your employer sets it up for you and diverts a percentage of your salary, pre-tax, into it from each paycheck. Your employer might even match some percentage of your contribution. In addition to the IRS’s qualified medical expenses, you can use FSA funds to pay for co-pays and deductibles, but not premiums.

This might sound like a better deal than an HSA, but there’s a catch: If you don’t spend your FSA money by the end of the year, you’ll lose some or all of it. Your employer can let you carry over any unused money until March 15 of the following year, or can let you keep $500 of it indefinitely. S/he can’t do both.

If you have an HSA, you must file IRS Form 8889 with your income taxes.

Want to learn how to invest?

Get a free 10 week email series that will teach you how to start investing.

Delivered twice a week, straight to your inbox.