Spain is a member of the Schengen Agreement. For EU and EFTA (Iceland, Liechtenstein, Norway, Switzerland) citizens, an officially approved ID card (or a passport) is sufficient for entry. In no case will they need a visa for a stay of any length. Others will generally need a passport for entry.
There are no border controls between countries that have signed and implemented the treaty - the European Union (except Bulgaria, Cyprus, Ireland, Romania and the United Kingdom), Iceland, Norway and Switzerland. Likewise, a visa granted for any Schengen member is valid in all other countries that have signed and implemented the treaty. But be careful: Not all EU members have signed the Schengen treaty, and not all Schengen members are part of the European Union.
Airports in Europe are thus divided into "Schengen" and "non-Schengen" sections, which effectively act like "domestic" and "international" sections elsewhere. If you are flying from outside Europe into one Schengen country and continuing to another, you will clear Immigration and Customs at the first country and then continue to your destination with no further checks. Travel between a Schengen member and a non-Schengen country will result in the normal border checks. Note that regardless of whether you travelling within the Schengen area or not, some airlines will still insist on seeing your ID card or passport.
Keep in mind that the counter begins once you enter any country in the Schengen Area and is not reset by leaving a specific Schengen country for another Schengen country, or vice-versa.