Citizens Advice Spain have a fantastic article on this https://www.citizensadvice.org.es/the-procedure-for-the-tie-foreigners-id-card-application/