A visa for Germany is always issued for a particular purpose. Students apply for a student's visa or for a visa as an applicant for a university place. To do this you have to contact either the German Embassy or the German Consulate General in your home country. Do not enter Germany with a tourist visa - you will not be able to convert it to a residence permit once you are in Germany!
In any case to get a visa you need a passport, a notification of admission or, as the case may be, a confirmation of your application from your German university or university of applied sciences and, most importantly, proof that you can finance your studies. The German Embassy or the German Consulate General can inform you of any further requirements.
If you already have a notification of admission to study then you can apply for a student's visa. However, the notifications of admission from Germany often come rather late - in this case you should apply for a visa as an applicant for a university place. For the latter you must show confirmation that you have applied to a German university.
The visa is valid for three months; once you are in Germany you must have it converted into a residence permit for the purpose of studying.
Often it can take several months for a visa to be issued, so make sure that you apply for it well in advance! If your arrival in Germany is delayed you might miss important deadlines and may no longer be able to enrol. Without enrolment you cannot get a residence permit for the purpose of studying.
Frequently asked questions: Studying in Germany
Where must I apply for a visa?
Websites of the German diplomatic representations abroad.
Visa application forms on the internet
You will find further information on visa procedure, entry into Germany and application forms on the website of the German Foreign Office.