The initial certificate is valid for 5 years. After 5 years of continuous and legal residence in Spain, you can apply for the EU Citizen Permanent Residence Certificate, which is valid for 10 years and renewable.
Your right to reside in Spain as an EU citizen does not expire as long as you meet the conditions. The certificate is a registration, not a permit: your right comes from the EU Treaty.