A Spanish notary will not sign the purchase deed without an NIE for every buyer named on it. That is the practical answer, and it is why the NIE is usually the first piece of Spanish paperwork a buyer deals with.
Why it's needed
The NIE identifies you to Spanish administration. In a property purchase it appears on the deed, on the transfer tax return, on the utility contracts, on the community fee arrangements and on the annual non-resident tax return afterwards. Without it, none of those things can be completed in your name.
When to start
As soon as you have something in writing about the property — typically a reservation contract or a deposit contract (contrato de arras). That document also serves as your proof of why you need the NIE, which is one of the required documents.
Do not wait for the completion date to be fixed. Appointment availability in the provinces most popular with foreign buyers is exactly where waits are longest, and a delayed NIE can put a deposit at risk if the contract has a completion deadline in it.
Joint buyers, spouses and children
Each person named on the deed needs their own NIE.A couple buying together needs two. If children are named as co-owners, they need one each as well, applied for by a parent or guardian with the birth certificate and the parent's identification.
If you're getting a Spanish mortgage
The bank will need your NIE to open the account the mortgage is paid from and to run its checks. This effectively brings the deadline forward: you need the NIE before the mortgage process rather than before completion.
Can my lawyer do it for me?
Yes, and it is one of the most common uses of the representative route. You give your Spanish lawyer or gestor a power of attorney and they submit for you.
Many buyers already grant one for the purchase itself, and it can often be drafted to cover the NIE too.
Signing outside Spain? Factor in the notary fee, the Apostille and a sworn translation.
After completion
You will keep using the number: transfer tax, moving utilities into your name, the annual non-resident income tax return, and eventually selling.
Keep a scan of the certificate. The number never expires, but some banks and notaries want one issued in the last three months or so.
A word on timing promises
If a service guarantees your NIE before a fixed completion date, be careful. Appointment availability and processing times sit with the Spanish authorities.
What a good service does: start early, submit correctly first time, and tell you honestly if your deadline looks tight, so you can talk to your lawyer in time.