It seems some people in the UK have been turned away from their flights for not having the correct documentation. (Yet another Brexit benefit🙄🙄) Passports are almost always necessary (within schengen a valid ID card is fine) and depending on where you're traveling the passport must have at least 3, or 6, months left before it expires.
All countries will have their own rules concerning passport validity and expiration rules.
When visiting the European Union For most European countries, HM Passport Office recommend that on the day you travel you have at least three months left on your passport. This obviously includes Spain
Your passport must be machine readable, with two blank pages for your visa and valid for a minimum of 180 days at the end of your trip.