"We have to buy more milk."
Translation:Tenemos que comprar más leche.
They are different words with different meanings and although they can be interchangeable colloquially, to be precise needing to do something and having to do something are not the same. You need to do something for your own purposes and you have to do something when someone or something else makes you to is maybe one way of distinguishing it.
From what I've been able to work out, if you have a "need" followed by an infinitive (a "to be" verb) then you use "tener que + to be". But if you have a "need" not followed by an infinitive, then you use "necesitar".
Example: I need + to buy bread = yo tengo que comprar pan. I need bread = yo necesito pan.
'Necesitar' can also be followed by an infinitive:
- Necesito estar libre. I need to be free.
- Necesitas hacer ejercicio. You need to exercise.
- Necesitan salir ya si quieren alcanzar su vuelo. You need to leave now if you want to make your flight.
- Necesitamos cenar. We need to have dinner.
- Necesito ir al supermercado para comprar leche. I need to go to the supermarket to buy milk.