As a non-European Union resident, you can request a refund of the Value Added Tax or VAT (in Spain, IVA) paid on your purchases. You just need to fill in the Tax-Free form in the shops where you buy them. Then, get the form validated at Customs within 3 months of the purchase date.
From 1 January 2019 the electronic DIVA system is the only valid procedure for validating invoices at Customs. This new system speeds up the process of validating the documents and refunding the tax. With this method, you just have to ask the shops offering this service to provide the DIVA web form, and validate it directly at the automatic terminals installed in many airports and in Spain’s main ports and land border Customs.
You also have the option of getting your VAT refund in advance, before stamping in the customs office on the last day, through Global Blue. This company has offices and information points ready to do this job in the following city centres: Madrid, Barcelona, Valencia, Girona, Tarragona, Lloret de Mar and Puerto Banús.
You can see all the requirements for getting VAT refunds in this Spanish Tax Agency leaflet.
More information on the DIVA electronic tax free system.
Informational video on the Spanish Tax Agency’s DIVA system.
Consult the list of Spanish airports and ports offering the DIVA service.