A taxpayer is considered to reside in Spanish territory when he spends more than 183 days in Spain in a calendar year or when the main base of his business or professional activities or economic interests is in Spain.
Workers assigned abroad: Personal Income Tax legislation establishes a very large exemption on income earned by workers who are tax resident in Spain but work abroad for a non-resident company or entity, or a permanent establishment abroad. This exemption applies to up to 60,100 euros a year, provided certain requirements are met.
More information on Personal Income Tax