Assuming you don’t have Spanish citizenship, you’re a resident if either:
- You’re physically present in Spain for more than 183 days (including sporadic absences).
- The main base of your professional activities or economic interests are in Spain.
Note if you are Spanish resident you should pay taxes for you income coming from everywhere. If you are non resident you have to pay taxes in your country for your income coming from Spain. The most common is to have a property in Spain and rent it out.