But Mr. Farrell unknowingly ran afoul of one of the complex rules that govern the transition to Medicare — and now he is paying the price.

Medicare requires enrollees to sign up during a limited window before and after their 65th birthday. Failing to do so leads to stiff late-enrollment penalties that continue for life, and potentially expensive, long waits for coverage to begin. There is one major exception: People who are still employed when they turn 65 can stay with employer-provided group coverage.

What Mr. Farrell missed is that Cobra coverage did not qualify him for that exemption, since he was no longer actively employed. He didn’t realize his error for more than a year, when the end of his Cobra coverage approached and he began looking into Medicare. The mistake means that he will pay a late-enrollment penalty equal to 20 percent of the Part B base premium for the rest of his life. This year, the penalty increases his monthly standard premium of $135.50 to $162.60.

The transition to Medicare from other types of insurance is plagued by problems like Mr. Farrell’s — and, so far, there isn’t much of an early warning system to alert people close to retirement age of the pitfalls. These complex rules also affect people moving from Affordable Care Act exchange plans and retiree health coverage. And workers who use Health Savings Accounts in conjunction with high-deductible employer insurance need to watch out for tax issues related to timing.

The basics on signing up

Medicare enrollment in Part A (hospitalization) and Part B (outpatient services) is automatic if you have claimed Social Security benefits before your 65th birthday — your Medicare card will arrive in the mail and coverage begins the first day of the month in which you turn 65. There is no premium charged for Part A in most cases, and you may be able to turn down Part B at that point without incurring late-enrollment penalties if you are still working and receive your primary insurance through work.