Applying for an F-1 or M-1 student visa for study in the U.S. is not normally a lengthy process. Nevertheless, you will need to figure out two separate calendaring issues:
Your school will likely provide you with helpful information and support during the visa application process, but ultimately it will be up to you to deal with the U.S. government in applying for a U.S. student visa.
If you are applying to academic programs (requiring an F-1 visa), it's normally best to start contacting schools at least a year before you plan to start your studies. The school year usually starts in August or September.
Competition for entry to schools in the United States can be fierce, especially if they are big-name schools like Harvard or Stanford. You will probably want to submit between five and ten applications to a mix of schools, including some that you know you have a good chance of being admitted to.
If you are planning to apply to a vocational program (requiring an M-1 visa), the calendar will not be so predictable. You will need to contact schools directly for information on admission and scheduling.
Only after the school has admitted you and issued a SEVIS Form I-20 can you take the next step and apply for your student visa. For guidance, see Student and Exchange Visitor Visas.
One of the risks you face is that you'll apply too late. The U.S. consulate might not issue your visa decision, or the visa itself, on the same day as you appear in person to apply, assuming an interview is required in your case.
(In 2021, the Department of State announced that consular officers can waive the visa interview requirement for certain F, M, and academic J visa applicants. This includes applicants who were previously issued any type of visa, and who have never been refused a visa (unless such refusal was overcome or waived), and who have no apparent ineligibility or potential ineligibility; or for first-time F, M, and academic J visa applicants who are citizens or nationals of a country participating in the Visa Waiver Program (VWP), provided they have no apparent ineligibility or potential ineligibility.)
In some cases, applications are referred for further administrative processing, which can take up to 60 days or more from the consular interview date to be resolved. Check with your local U.S. consulate for its suggestions on timing and application procedures. Many recommend applying three to six weeks in advance of your intended travel.
If you are already in the U.S. and in lawful status, and you would prefer to switch to student status without leaving for your home country, you can potentially do so by submitting a form called an I-539. In that case, you will not be dealing with a U.S. consulate, but with U.S. Citizenship and Immigration Services (USCIS), in the United States. (Be aware, however, that applying for this from B-2 visitor status is frowned upon.)
You will need to check into how long the USCIS office that will handle your request is taking to process Forms I-539, for a change of status. To find this out, go to the Check Case Processing Times page of the USCIS website and review processing times for the service center where your case is being handled.
As you will see from USCIS's instructions for Form I-539 (in the "all other Forms I-539" category), you will submit your application to a "lockbox" in Texas.
When you receive your filing confirmation via U.S. mail, it will have your case number. Case numbers beginning with WAC are for California; YSC refers to the Potomac Service Center; LIN refers to cases at the Nebraska Service Center; and TSC is the Texas Service Center. Reviewing the relevant Service Center's processing times in advance will give you an idea of how long it will take USCIS to process your I-539 application.
As of early 2022, USCIS was taking between 17 and 19 months to process change of status applications for F-1 and M-1 students, depending on service center. You would want to apply early enough to deal with this timeframe.