In short: you can apply for Spanish nationality by residence depending on years of legal residence: 10 in general, 5 refugees, 2 Ibero-Americans and similar, 1 in cases with a Spanish link. You must pass the CCSE and DELE A2 exams and show good conduct.
In person or by representative? The procedure is telematic: it is filed online at the Ministry of Justice's electronic office (with a digital certificate or Cl@ve). Separately, the CCSE and DELE A2 exams are taken in person.
Continuous legal residence periods:
- 10 years — general regime.
- 5 years — refugees.
- 2 years — nationals of Ibero-American countries, Andorra, the Philippines, Equatorial Guinea, Portugal, and Sephardim.
- 1 year — those born in Spain; married to a Spaniard; children/grandchildren of a Spaniard by origin; widow(er) of a Spaniard, among others.
Exams (Instituto Cervantes):
- CCSE (constitutional and sociocultural knowledge): pass 15 of 25 questions; valid 4 years.
- DELE A2 (Spanish language): only if you come from a country where Spanish is not an official language.
Other requirements: good civic conduct; birth certificate and criminal-record certificate (with Hague apostille or legalisation, and sworn translation).
Filing and timing: filed with the Ministry of Justice (electronic office). Legal resolution period: 1 year (in practice, 12-24 months).
Official source: Nationality by residence — Ministry of Justice.
Informational only; exact requirements and exemptions vary — check the official source and a professional for your case.