You spend more than 183 days in Spain during one calendar year. You become liable whether or not you take out a formal residence permit (Residencia). These days do not have to be consecutive. You do not become resident for tax purposes until the morning of the 184th day.
Temporary absences from Spain are ignored for the purpose 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.