If you want to live in Spain you need to know which are the needed requirements and therefore avoid problems afterwards. In Spain you can opt for a temporary or permanent residence in Spain.
The temporary stay is for those living in Spain for a period longer than 90 days and shorter than five years which can be renewed depending on the circumstances. People who can opt for a temporary residence are those foreigners who have sufficient means of subsistence for themselves and their family.
The permanent stay (long-term residence) allows foreigners to work and live in Spain under the same conditions as Spaniards. Moreover, those foreigners who have resided in Spain for an uninterrupted period of five years can opt for the long-term residence as well.
Source: Spanish Ministry of Foreign Affairs and Cooperation