We research all brands listed and may earn a fee from our partners. Research and financial considerations may influence how brands are displayed. Not all brands are included. Learn more.

Getty Images

If you are 65 or older and file for Social Security, the government will also sign you up for Part A of Medicare.

Normally, this would be no big deal. There are no premiums for Part A hospital coverage for people who have worked long enough to qualify for Social Security. And if you are still working, in most cases you don’t even need Medicare when you turn 65.

But if you have a tax-deductible health savings account (HSA) and are on Medicare, you will no longer be able to make contributions to it. In fact, the IRS rules say you need to stop contributions six months before Social Security benefits begin, although I’ve never heard from anyone who lost tax benefits or was hit by an IRS penalty for such contributions.

The rule on Medicare and HSA contributions isn’t new, but it is snaring more people. Not only are more people staying in the workforce well into their 60s and even 70s, but high-deductible health plans that often include HSAs have become very popular.

So, what once was a footnote problem is now a headline. Here is what you need to know about these rules to avoid getting tripped up.

HSAs are available to most people who sign up for a high-deductible health plan from an employer. These accounts offer a tax-advantaged way of paying current health expenses and can be a terrific retirement savings vehicle for people who don’t rack up large out-of-pocket medical expenses.

Pre-tax contributions in 2016 can be up to $6,750 for a family health plan and $3,350 for a single person, plus up to $1,000 per person in “catch-up” contributions for people 55 and older.

The funds can be placed in 401(k)-type investment accounts. Many employers sweeten the deal by making their own contributions to an employee’s HSA. (These employer contributions are counted toward the annual ceilings.)

Neither the contributions nor investment gains will ever be subject to federal income taxes so long as account distributions are spent on qualifying medical expenses. Better still, each year any unused balances in the accounts aren’t lost but roll over to the next year and beyond. Properly managed, these accounts can be great sources for paying post-retirement health bills.

The problem for some HSA fans is that at age 65 or later, it isn’t possible to sign up for Social Security and opt out of Medicare Part A. The only way to reject Part A is to disenroll in Social Security and halt your retirement payments. In most cases, doing this would not permit you to get higher payments later. You’d just lose the payments you had been receiving.

As a result, rejecting Social Security is a lousy way to avoid losing the ability to make HSA contributions. Losing HSA tax benefits is not nearly so big a financial hit as losing Social Security payments.

There’s good news for couples in which both spouses are covered by a high-deductible health plan and one is not yet on Medicare. In that case, they could still participate in the HSA. And all of the allowable annual family contributions to the plan would still be allowed, save for the $1,000 catch-up contribution from the spouse enrolled in Medicare.

Even if the non-Medicare spouse is not an employee of the organization providing the HSA plan, an IRS spokesman confirmed to me, these contributions would still be tax-deductible under its rules.

Note that while continued contributions to HSAs are disallowed for people on Medicare, these individuals can still use existing balances in their acounts to pay for qualified health care expenses, including Medicare premiums.

Read next: Why Is My Spousal Social Security So Small?

If you expect your HSA contributions to be disallowed in the future, you should explore different health plans with your employer. And if your employer has been willing to contribute funds to your HSA, ask if comparable support is available in another plan.

Personally, I believe there should be a better and less confusing way forward here. The health expenses of every new user of Medicare are subsidized by Uncle Sam, and that’s us taxpayers, folks. Shouldn’t the government be happy to keep people on employer-provided insurance as long as possible? Forcing them out of HSAs hardly seems a wise move in that respect.

UPDATE: I heard today from a 69-year-old reader who wasn’t aware of the HSA/Medicare rule. He’s been receiving Social Security since he turned 66 and signed up for an HSA two years ago.

Here is part of my response to him:

Philip Moeller is an expert on retirement, aging, and health. He is co-author of the recently updated New York Times bestseller, “Get What’s Yours: The Revised Secrets to Maxing Out Your Social Security.” His companion book, “Get What’s Yours for Medicare: Maximize Your Coverage; Minimize Your Costs,” will be published this fall. Reach him at moeller.philip@gmail.com or @PhilMoeller on Twitter.