Signing up for Medicare
When should I apply?
If you’re already getting Social Security benefits, or railroad retirement checks, we’ll send you information a few months before you become eligible for Medicare.
If you’re not already getting benefits, you should contact Social Security about three months before your 65th birthday to sign up for Medicare.
Reference:
https://www.ssa.gov/pubs/EN-05-10043.pdf
Individuals already receiving Social Security or RRB benefits at least 4 months before being eligible for Medicare and residing in the United States (except residents of Puerto Rico) are automatically enrolled in both premium-free Part A and Part B. People who are automatically enrolled have the choice whether they want to keep or refuse Part B coverage. People living in Puerto Rico who are eligible for automatic enrollment are only enrolled in premium-free Part A; they must actively enroll in Part B to get this coverage.
Individuals who are not receiving a Social Security or RRB benefit are not automatically enrolled.
Reference:
https://www.cms.gov/Medicare/Eligibility-and-Enrollment/OrigMedicarePartABEligEnrol/