If you want to reside, work, study or carry out a research in Spain you must apply for the long-term visa unless you are a citizen of the European Union, Iceland, Liechtenstein, Norway or Switzerland.
To apply for a long-term visa you must fill in an application form which can be downloaded from here.
Visas can be acquired in person or by an accredited representative at the Spanish Diplomatic Mission or Consular Post of your area.
When submitting the application form, a fee must be paid (60€) which will not be refunded whether the visa is denied or not. Moreover, those people interested in living in Spain must obtain information about the different procedures from the relevant bodies, such as the Ministry of Interior and the Ministry of Employment and Social Security.
The deadline for this long-term visa is of one month after the application form has been submitted, except the non-lucrative residence visas, in which the deadline shall be of three months.
If the visa is issued, it must be collected in person at the relevant Diplomatic Mission or Consular Post, although If it is impossible for the person to come, an authorized representative can collect it as well.
However, if the visa is refused, the applicant will be notified by means of a standard form indicating the grounds for the refusal.
Source: Spanish Ministry of Foreign Affairs and Cooperation