It is relatively simple to get a Social Security Number in Spain (Número de afilicaion a la seguridad social).
First of all, locate your nearest social security office (Tesorería General de la Seguridad Social – TGSS), you can find a list of them here.
You will need (copy and original of):
• Your passport
• Your NIE / Residency document
• TA.1 form
*Remember that if you want to include beneficiaries, such as your spouse and/or children, you must also take copies and original of their documentation.
*If you are going to register as Self Employed (Autonomo), you will also need to take your bank account details, to set up automatic payments each month.

Info from