From Mark’s post under “Are you a resident in Spain for tax purposes?”
You will become resident for tax purposes in Spain if:
You spend more than 183 days in Spain in one calendar year. You become liable whether or not you take out a formal residency permit. These days do not have to be consecutive. (Temporary absences from Spain are ignored for the purposes of the 183-day rule unless it can be proved that the individual is habitually resident in another country for more than 183 days in a calendar year.)
*Or, your “centre of vital interests” is in Spain, e.g., the base for your economic or professional activities is in Spain.
*Or, your spouse lives in Spain and you are not legally separated even though you may spend less than 183 days per year in Spain
I’ve read this elsewhere as well.