The short answer: Three Months.
A little explanation: Medicare enrollment begins 3 months before your 65th birthday (well, the month of your birth) and ends 7 months from your birth month. If you aren’t already enrolled and receiving Social Security, you will need to sign up during this period. If you are receiving Social Security checks, you will be automatically enrolled upon turning 65. If you live in Puerto Rico, you will only receive part A automatically, and will have to sign up for Part B yourself if you want that benefit. If you live elsewhere in the United States and you are receiving Social Security, you will be automatically enrolled in Part A and Part B.
Want more information? Here is a government reference to get you started with Medicare.
And here is more information about the sign-up periods for Part A and Part B.
If you have further questions, call Your Insurance Gal Agency and talk to a local agent who is happy to help walk you through the entire enrollment process.