A NIE - a Número de Identidad Extranjero or Foreigner’s Identity Number - is a tax number given to all non-Spanish citizens who need to carry out any procedures with the Spanish government, e.g. study, work, buy property, open a bank account in Spain.
You need a NIE if:
In some ways, there is no rush to get a NIE; the authorities will not check to see if you have one, but you will not be able to do some simple tasks - such as open a bank account - without one. Some companies will not even offer you a work contract if you do not have one, so it’s better to get it sorted sooner rather than later.
You need to apply for a NIE using the EX-15 form. Find out the process in detail here.
If you need a visa to stay in Spain, you do not need to apply for a NIE as it will be issued on your entrance visa. In this case, you need to apply for a Tarjeta de Identidad de Extranjero (Foreigner’s Identity card) within one month of your arrival in Spain.
If you need a NIE but do not reside in Spain, you can apply at the Spanish consulate in your home country or grant someone in Spain power of attorney to apply on your behalf (lawyer, notary etc.). You can also apply in person in Spain using the EX-15 form.