Whether you need a German student visa depends on your country of origin. If you are from a country within the EU or the EEA or from Switzerland, Norway, Iceland or Liechtenstein, you do not need a student visa. If you are from the US, Canada, Australia, New Zealand, Israel, Japan or South Korea you still do not require a student visa, but you will need to register for a residence permit upon arrival in Germany. If you are from Andorra, Brazil, El Salvador, Honduras, Monaco, San Marino or Taiwan, you only need a visa if you plan on working in Germany before or after your studies. If your home country hasn’t been mentioned above, then you will need to apply for a German student visa at least three months before you are due to travel.
For detailed information on how to apply for a German student visa or a residence permit, check out this article: