Through socialisation, people learn their position with social hierarchy. Individuals understand their position relative to those people who are above and below them.
Most people generally accept the legitimacy of authority is needed for society to function properly, such as recognising the right of police or judges to give orders.
Legitimacy of authority is communicated through visible symbols such as uniforms or settings.
We may obey people with legitimate authority because we trust them. Alternatively, we may obey them because they have the power to punish us.