Here are the most common situations that lead to costly errors.

IF YOU’RE STILL EMPLOYED AT 65 People who are actively employed at age 65, and their spouses, may delay enrollment in Medicare. The key word here is “active,” as Mr. Farrell discovered. “Cobra does not count as active employer group coverage,” said Philip Moeller, author of Get What’s Yours for Medicare: Maximize Your Coverage, Minimize Your Costs. “If you lost your employer coverage, you still need to sign up for Medicare when you turn 65.”

There is one other exception to the active employment rule: If you work for a company with 20 or fewer employees, Medicare becomes the primary payer, so sign up when you turn 65.

“Insurers and employers audit this regularly, and if you become seriously ill, the insurer will realize you should have been on Medicare,” Mr. Baker said. “They will refund your premiums but they also can claw back any payments they may have made that should have been covered by Medicare.”

IF YOU HAVE A HEALTH SAVINGS ACCOUNT More employers are offering high-deductible health insurance plans, and that is creating an additional complication for some workers when they retire and enroll in Medicare. These plans often are paired with tax-preferred Health Savings Accounts (H.S.A.s), which accept contributions from employers and workers to offset out-of-pocket expenses.

H.S.A.s can accept contributions only from people enrolled in high-deductible plans — and Medicare does not meet that definition. Contributions must stop when you enroll in Medicare, although withdrawals can continue, and you’ll owe taxes on any disallowed pretax contribution that you may have made. And the timing can be complicated, because Medicare Part A coverage is retroactive for six months for enrollees who qualify during those months. For those enrollees, H.S.A. contributions must stop six months before their Medicare effective date in order to avoid tax penalties.

IF YOU ARE INSURED UNDER THE AFFORDABLE CARE ACTAnother common error is sticking past age 65 with a commercial policy obtained through the Affordable Care Act marketplace exchanges.

Federal law requires that you switch to Medicare at age 65. Like Cobra, marketplace coverage is secondary to Medicare; switching to Medicare later must be done during the General Enrollment Period, leaving you exposed to possible long coverage delays like the one experienced by Mr. Farrell — plus penalties.