Different regulations apply depending on the length of your studies, research or related activities in Spain.
Non-EU/EEA/Swiss citizens studying in Spain for less than three months (90 days) If you’re coming to study or carry out academic research in Spain for less than three months (90 days), you don’t need a visa for the purpose of study unless you come from a country for which a visa is required to enter Spain normally. You can find out if you need an entry visa for Spain in Expatica’s complete guide to Spanish visas and permits.
Note: You can’t come to Spain on a short-stay tourist visa and then apply for a student visa. You have to return to your home country and apply from there. Non-EU/EEA/Swiss citizens studying in Spain for between three and six months If your study programme lasts between three and six months you may be required to obtain a student visa but if it is stamped ‘180 days total studies’, you won’t be able to get a residence card/ tarjeta de identidad de extranjero (TIE) (Foreigner Identity Card) that will allow you to work in Spain.
Non-EU/EEA/Swiss citizens studying in Spain for more than six months If you’re studying in Spain for more than six months, then you’ll need to get a student visa (type D) and a student’s residence permit/card or Foreigner Identity Card (TIE) within 30 days of your arrival in Spain from your local Foreigner’s Office or police station.
Once you have a confirmed place on a course, you can apply for a study visa at the Spanish consulate or embassy in your home country. You’ll need to apply for your visa between two and three months before you intend travelling to Spain to allow time to process your application.
Exactly what is required may vary from consulate to consulate but in general you’ll need to show your passport, as well as the following: