If you wish to realise studies at a Spanish University or spend time here for a language class, you have to apply for a student visa. The Student Visa allows you to stay in Spain for the duration of the course or for one year. It is renewable annually.
The application for the student visa can be presented at the Consulate in the applicant's country of residence or, in case they are already legally in Spain under a tourist or Schengen Visa, it can be apply for online, as long as the application is presented before the last 30 days of the visa or other stay permit begin.
Please note that this is a stay permit and not a residence permit. The time you spend in Spain on a student visa is not taken into account for the permanent residence permit or the application for Spanish citizenship through residence.
In order to apply, you have to present a letter of admission from an authorised university or school and any additional documents required for you to realise the studies (payment confirmation of tuition fee etc.).
Furthermore, you have to accredit disposing of the following amounts for your maintenance:
For your monthly upkeep: 564,90 €/month
For each family member: 282,45 €/month
After 3 years, you can apply for a residence and work permit.
Another option you have is to apply for a Job Search Residence Permit to allow you to stay in Spain while applying.
The easiest way to go, if you are willing to start with an internship, is to apply for the Internship Residence Permit.