Healthcare is a major burden for workers and retirees alike. Even those with good insurance struggle to keep up with premium costs, deductibles, and co-pays.

Thankfully, tools like health savings accounts, or HSAs, can help workers set aside funds for medical expenses. To be eligible for an HSA, you must be enrolled in a high-deductible health plan. For the current year, that's defined as $1,350 for an individual, or $2,700 for a family.

If you qualify to fund an HSA, you can contribute up to $3,500 as an individual, or up to $7,000 for a family this year. And if you're 55 or older, you get an extra $1,000 catch-up on top of either limit.

Document labeled HSA with pen sitting on it on wooden surface with notebook, calculator, and glasses

Image source: Getty Images.

The benefit of funding an HSA is the tax advantage. Your contributions go in tax-free, shielding a portion of your income from taxes up front. That money can then be invested for tax-free growth, and if you spend those funds for qualified medical purposes, your withdrawals are tax-free as well.

But let's say you need money for a nonmedical expense, and you don't have it in the bank. You may be tempted to tap your HSA, but before you do, understand that there could be some pretty serious consequences.

Nonmedical HSA withdrawals

It's pretty difficult to overfund an HSA. Unlike flexible spending accounts, HSAs don't require you to use up your balance from year to year. In fact, the whole point is to contribute more money than you think you'll need on a short-term basis so you can invest it and grow it tax-free.

However, you might need cash, and you don't have it in another account. You also might think it's a good idea to take an HSA withdrawal rather than, say, rack up credit card debt -- why take on debt when you have money in an account?

Simple: The purpose of an HSA is to set aside funds for healthcare, so the IRS doesn't take kindly to withdrawals for other purposes. As such, if you remove funds for nonmedical expenses and you're younger than 65, you'll be taxed on the amount you withdraw, and worse yet, you'll also face a 20% penalty on that sum.

If you're already 65, and you take a nonmedical HSA withdrawal, you will be taxed on the funds you remove, but you'll avoid the 20% penalty. In this regard, you really have nothing to lose, because unless you house your retirement savings in a Roth IRA or 401(k), the same rule applies: You pay taxes on the withdrawals you take.

If you're not yet 65 but are at least 59 1/2, and you have money in an IRA or 401(k), then you're much better off removing funds from one of those accounts and leaving your HSA alone. As long as you're at least 59 1/2, you won't face an early withdrawal penalty on an IRA or 401(k) distribution, even if you aren't retired yet.

Furthermore, if you're under 59 1/2 and must withdraw funds from a tax-advantaged savings account, you're actually better off tapping your IRA or 401(k) and leaving your HSA alone. While you will face an early withdrawal penalty, it's only 10%, whereas the penalty for early HSA withdrawals is double.

If you're desperate for money, are under 65, and are thinking of raiding your HSA, it pays to explore all the alternatives first. Otherwise, you'll face a major penalty on your withdrawal, not to mention taxes. Just as important, the more money you remove from your HSA for nonmedical purposes, the less you'll have when healthcare costs pop up. And that could hurt you financially during your working years as well as retirement.