Spanish citizens keep their identity card number which allows them to identify them, for life, a bit like the social security number in France. They issue the equivalent to foreigners. You may obtain it at the Police Headquarters or at the Spanish Consulate abroad.