There's a reason so many people worry about not having enough money in retirement. The idea of giving up a paycheck and having to live on a fixed income can be scary given the potential for living costs to increase over time.

Retirement is also a period of life when health issues tend to emerge, making medical care even more expensive. Between that and the many costs seniors commonly incur under Medicare, it's to see why future healthcare expenses have many people worried.

A person at a laptop.

Image source: Getty Images.

That's why it pays to contribute to a health savings account, or HSA, if you're eligible to do so. HSAs allow you to contribute pre-tax dollars for medical spending. You can invest funds you don't need right away and grow your balance tax-free. And withdrawals are tax-free as long as they're used for medical spending.

Best of all, HSA funds never expire, so you can put money into one of these plans during your working years and reserve all of that money for retirement. If you're able to go this route, it pays to do so. Here's why.

1. Your healthcare costs could be really enormous

Last year, Fidelity estimated that the average 65-year-old couple entering retirement would need $315,000 in savings to cover their healthcare costs throughout their senior years. But you might end up spending even more than that if health issues arise.

If you fund your HSA and leave that money alone through the years, all the while investing it, it might grow into a large enough sum to cover several hundred thousand dollars' worth of expenses. But if you keep taking HSA withdrawals as you go, you'll have less money to carry with you into retirement.

2. You can take penalty-free withdrawals for any purpose once you turn 65

You might end up accumulating a very large sum of money in your HSA. And if you end up in the very fortunate position of not needing all of it for medical spending, you have options there, too.

Once you turn 65, HSAs allow you to take withdrawals for non-medical spending without incurring a penalty. Prior to age 65, a financial penalty will apply.

Now if you take a non-healthcare-related HSA withdraw at age 65 or older, you'll have to pay taxes on it. But in that case, you're in no worse shape than you would be for tapping a traditional 401(k) or IRA.

Although not everyone can contribute to an HSA, since eligibility is based on being enrolled in a compatible, high-deductible health insurance plan, it pays to fund one of these plans consistently if you can. But more so than that, do your best to leave your HSA alone so you can bring as much money into retirement as possible for healthcare spending purposes.

Having a sum of money earmarked for medical spending could make the idea of ending your career much less stressful, not to mention give you more wiggle room once you enter retirement and potentially have to exist on a more limited budget.