Whenever you hear someone talking about the NIE in Spain, they usually mean either the residence permit of a foreigner or the physical card representing said permit.
This often leads to confusion because NIE actually means "Número de Identidad del Extranjero" which means "foreigner identity number". So, the NIE is only the specific sequence of numbers and letters that a foreigner gets who has business in Spain. It is a code for the tax identification of foreigners in Spain. Thus, you need a NIE for any operation that may lead to you having to pay taxes in Spain.
The physical card the non-EU foreigner is issued is called the TIE, "Tarjeta de Identidad del Extranjero" ("Foreigner Identity Card").
The NIE can be issued in different ways depending on the situation of the foreigner:
The NIE can be issued on its own as a so-called non-resident NIE to a foreigner who does not apply to reside in Spain but only wants to realise some economic transaction here. For example purchase a property or a car.
In case of EU Citizens, the NIE is displayed on their EU Registry Certificate.