Okay, so, surprise surprise, the official and universal language in Spain is Spanish. But it does get more complicated than that. Because Spanish is part of the Romance family of languages, some people like to call it Castilian.
Elsewhere in Spain there are a number of other languages spoken depending where you travel, including Catalan, Basque, Galician, and more. Some of these languages are co-official with Castilian in their respective regions. Many of these are pretty easy to pick up if you know Castilian, although locals will still speak that, too. Still, it doesn't hurt to learn a few words of the local lingo.
Catalan is mainly spoken in Catalonia (surprisingly) to the east, Valencia, and the Balearic Isles. Galician is closely related to Portuguese and you'll come across it if you're backpacking in Galicia or the western portion of Asturias. Basque is completely unrelated to any other known language in the world, and is spoken in the three provinces of the Basque Country - Alava, Biscay, and Gipuzkoa.
Other languages in Spain include Asturiano, Aragonese, and Aranese.
English and French are commonly studied in Spanish schools, but profiency varies heavily depending on where your gap year takes you - the majority in big cities speak English well, while in rural areas the level is quite poor.
Portuguese and Italian are closely related to Spanish, so if you speak either of those languages the locals might be able to puzzle you out. Just make sure to speak slowly and clearly (but not patronisingly loud).