If you are from a member-country of the Schengen agreement - Austria, Belgium, the Czech Republic, Denmark, Estonia, Finland, France, Germany, Greece, Hungary, Italy, Latvia, Lithuania, Luxembourg, Malta, the Netherlands, Poland, Portugal, Slovakia, Slovenia, Spain, Sweden, plus Iceland and Norway (which are not EU members)- you do not need a passport to enter Spain. An official national ID card will suffice.
Citizens from EU countries that do not form part of the Schengen agreement must carry a valid passport to enter Spain. These are the UK and Ireland, as well as new members of the EU that do not yet participate in Schengen are Cyprus (joined in 2004) and Bulgaria and Romania (joined in 2007).
If you are from any of the aforementioned countries, Switzerland or member-countries of the European Economic Area (Norway, Iceland & Liechtenstein), you do not need a special visa to enter or reside in Spain. If you are planning to stay for more than 3 months, however, you need to apply for a residence card.
Citizens of the following countries do not need a visa to stay in Spain for less than 90 days, only a valid passport: Andorra, Argentina, Australia, Austria, Belgium, Bolivia, Brazil, Brunei, Canada, Chile, Costa Rica, Croatia, El Salvador, Guatemala, Honduras, Hong Kong & Macao (China), Israel, Japan, Malaysia, Mexico, Monaco, New Zealand, Nicaragua, Panama, Paraguay, Singapore, South Korea, United States, Uruguay, Venezuela.
If you are from any of these countries and desire to stay in Spain to work or study for more than 3 months, you must solicit the corresponding visa. Agreements and processes vary by country, so it's best to consult the Spanish consulate closest to you.
Obtaining a student visa for Spain is not difficult, as long as your school provides the necessary paperwork. Apart from an official invitation letter you will need a certificate of good health, clean police record and proof of funds to pay for private insurance while in Spain.
Obtaining a work and residency visa is much more complicated and laws are constantly changing. The company in Spain must present the necessary paperwork to the Ministry of Labor here, including proof that no Spanish resident is capable of filling the position. The law now states that no illegal alien may solicit a work visa from within the country.