Everyone in Spain has to carry ID. The most usual way for Spanish nationals to do this is to carry their DNI, an identity card.
Youngsters don't have to hold a card until they are over 14 but it is usual to apply for a DNI for a child as soon as their birth is registered. If a family decides not to apply for a DNI for their child "at birth" then the details of the minor have to be entered in the "family book." Foreigners have to carry ID too, usually a passport.
Foreigners who are resident in Spain have to apply for an ID number as does anyone who wishes to carry out any financial transactions here whether they are resident or not.
The identity "number" for Spanish Nationals, the DNI, has 8 figures and just one control letter whilst the one for foreigners, the NIE, has a letter at both the beginning and the end with seven numbers in the middle. Spaniards are always surprised, nay shocked, to find that UK passport numbers change from issue to issue. Their Spanish ID numbers follow them through life appearing on passports, driving licences etc.
The Spanish ID card carries simple details like a photo, name, date of birth, place of birth, address, names of parents etc. Until recently it also carried a finger print but the newest cards carry the characteristics of that print in electronic form on a chip and also provide a digital signature for electronic transactions. So every Spaniard is fingerprinted - something currently reserved for criminals or suspected criminals (oh and motorists) in the UK.
Everyone, but everyone, thinks they have the right to see your ID. I needed it for eBay, I needed it to register my mobile phone, to sign on the dole, to rent a flat, to register in a hotel, to hire a car, to get a credit card, to pay by credit card, to open a bank account, to register for health care, to get gas bottles and even to join a classic car club.
You don't need to know you account number at the bank or your social security number at the tax office so long as you have your DNI/NIE. Everything, but everything, is connected to your ID number. Lots of official Spanish databases are linked and I suspect that it would be very easy for someone to access lots and lots of information about anyone living in Spain.
The Spanish ID card was introduced by Franco, a dictator. He got card number 1 and he left the numbers up to 100 for his family and for the Royals. Our King has number 10.