Yes, foreigners are legally permitted to purchase property in Spain under the same conditions as Spanish residents. You will need an NIE number, a Spanish bank account, and a proper legal due diligence process before completion. The purchase procedure is clear and well regulated when guided by an experienced local professional.
