Unsurprisingly, the official and universal language used in Spain is Spanish (español, castellano), but it's more complicated than that, as it differs from the Latin American varieties in pronunciation and other details. It is part of the Romance family of languages (others include Portuguese, Galician, Catalan, Italian, Occitan, French, and Romanian) and is one of the main branches of that family. It is more properly called Castilian (castellano).
However, there are a number of languages — Catalan, Basque, Galician, Asturian, etc — spoken in various parts of Spain. Some of these languages are dominant in their respective regions, and following their legalization in the 1978 constitution, they are co-official with Castilian in their respective areas. Of these, Catalan, Basque and Galician are recognised as official languages according to the Spanish constitution. Apart from Basque (whose origins are still debated) the languages of the Iberian Peninsula are part of the Romance family and are fairly easy to pick up if you know Castilian well. Learning a few words in the local languages where you are traveling will help endear you to the locals.
Catalan (Catalan: català, Castilian: catalán), is a distinct language similar to Castilian but more closely related to the Oc branch of the Romance Languages and is considered by many to be part of a Dialect Continuum spanning across Spain, France, and Italy and including the other Lengas d'òc such as Provençal, Beàrnais, Limousin, Auvernhat and Niçard. Various dialects are spoken in the northeastern region of Catalonia, the Balearic Islands, and Valencia (where it is often referred to as Valencià), east of Aragon, as well as neighboring Andorra and southern France. To a casual listener Catalan superficially appears to be a cross between Spanish and French, and though it does share features of both it is an independent language in it's own right.
Galician (Galician: galego, Castilian: gallego), very closely related to Portuguese, Galician is spoken in Galicia and the western portion of Asturias. Galician predates Portuguese and is deemed one of the four main dialects of the Galician-Portuguese family group which includes Brazilian, Southern Portuguese, Central Portuguese, and Galician.
Basque (Basque: euskara, Castilian: vasco), a language unrelated to Castilian (or any other known language), is spoken in the three provinces of the Basque Country, on the two adjacent provinces on the French side of the Spain-French border, and in Navarre. Basque is unrelated to any Romance language or to any branch of the Indo-European or Indo-Iranian family of languages. It currently remains unclassified and is deemed a linguistic isolate seemingly unrelated to any branch of the linguistic family tree.
Asturiano (Asturiano: asturianu, Castilian: asturiano, also known as bable), is spoken in the province of Asturias, where it enjoys semi-official protection. It was also spoken in rural parts of Leon, Zamora, Salamanca, in a few villages in Portugal (where it is called Mirandes) and in villages in the extreme north of Extremadura. While the constitution of Spain explicitly protects Basque, Balearic-Catalan-Valencian under the term Catalan, Galician, and Spanish, it does not explicitly protect Asturian. The province of Asturias explicitly protects it and Spain implicitly protects it by not objecting before the Supreme Court.
Aragonese (Aragonese: aragonés, Castilian: aragonés, also known colloquially as fabla), is spoken in the north of Aragon. It is only vaguely recognized, but not official (as of June, 2008). This language is close to Catalan (specially in Benasque) and to Castilian, with some Basque and Occitan (southern France) influences. Nowadays only a few villages near the Pyrenees use the language vigorously, while most people mix it with Castilian in their daily speech.
Aranese (Castilian: Aranés, Catalan/Aranese Occitan: Aranès), is spoken in the Aran Valley, and is recognized as an official language of Catalonia (not of Spain), alongside Catalan and Spanish. This language is a variety of Gascon Occitan, and as such is very closely related to Provençal, Limousin, Languedoc, and Catalan.
In addition to the native languages, English and French are commonly studied in school. While most younger Spaniards have studied English in school, due to a lack of practice and exposure, proficiency is generally poor, and most people will not know more than a few basic words. If lost, your best bet would generally be young urban people. To improve your chances of being understood, stick to simple words and avoid long sentences. That being said, major hotels and popular tourist destinations usually have staff members who speak an acceptable level of English, and particularly in popular beach resorts such as those in the Costa del Sol, you will find people who are fluent in several languages. As Portuguese and Italian are closely related to Spanish, if you speak either of these languages, locals would be able to puzzle you out with some difficulty, and as long as you speak slowly, you won't need an interpreter for the most part.
French is the most widely understood language in the north-east of Spain, like Alquezar and Cap de Creus (at times even better than English), as the majority of travelers there come from France.
Locals will appreciate any attempts you make to speak their language. For example, "Good morning" (Buenos días) and "Thank you" (Gracias).
If you are interested in learning Spanish, there are several options available. LSI (Language Studies International) offers quality Spanish courses in Spain.