"~요" is a formal ending for verbs. In the case of "안녕하세요" you are saying hello ("안녕") in a more polite way.
So "안녕" is typically used for friends and I believe can be used with family if you have that kind of casual relationship. However for older people, people you do not know, boss, or simply people you do not have a casual relationship with using the "~요" ending is much more polite.
Examples (of formal "요" in other sentences):
"주문하고 싶어요" - I would like to order please.
"지금 몇 시에요?" - What time is it right now?