Citizens of EU countries can enter Spain with their national identity card or passport. Citizens of the UK must have a full passport, not just a British visitor passport. Non-EU nationals must take their passport.
EU, Norway and Iceland citizens do not need a visa. Nationals of Australia, Canada, Israel, Japan, New Zealand, Switzerland and the USA need no visa for stays of up to 90 days, but must have a passport valid for the whole visit. This 90-day limit applies throughout the EU. South Africans are among nationalities that do need a visa.
It’s best to obtain the visa in your country of residence. Single-entry visas are available in flavours of 30-day and 90-day, and there’s also a 90-day multiple-entry visa, though if you apply in a country where you’re not resident, the 90-day option may not be available. Multiple-entry visas will save you a lot of time and trouble if you plan to leave Spain, then re-enter it.
Spain is one of the Schengen countries; the others are Portugal, Italy, France, Germany, Austria, the Netherlands, Belgium, Luxembourg, Sweden, Finland, Denmark and Greece. A visa for one Schengen country is valid for the others. Compare validity, prices and permitted entries before applying.
EU, Norway and Iceland nationals planning to stay in Spain more than 90 days are supposed to apply for a residence card during their first month in the country. This can be a complicated procedure; if you intend to subject yourself to it, consult a Spanish consulate before you go to Spain, as you’ll need to take certain documents with you.