It can really depend on the bird, and the circumstances.
As the others have said, birds can puff up to make themselves look bigger, to compete with rivals, to win over a mate, or to look larger and more intimidating against predators, so they are not eaten.
Birds will also sit (usually on one leg) puffed up when they are happy and relaxed. Quite often, you will hear them chirp happily while they are doing this.
Puffing out the feathers helps keep the bird warm.
A sick bird will also often perch puffed up, but they will normally not have the balance to perch on one leg, so they will perch with both of their legs.
To scare away potential predators. Also, its a sign that the bird could be sick.
They do it for a couple reasons. They do it to stay warm, they do it to look bigger than other birds, and they do it when taking a bath to dry off their feathers. If a bird's feathers are puffed for long periods of time, that means they are sick.
if its like a wild bird than its because to make their predators afraid of them and so they can look big and tough. if its like a pet bird it could be the same thing or my bird does it when she is super comfy and relaxed.
They do it stay warm. When they puff their feathers out it allows air to get between the feathers. Their body heat then heats the air and it acts in a similar way to us putting a woolen coat on.
Birds also puff up themselves when they get wet as it allows their feathers to dry out, if you've ever seen one washing itself in a bird bath they do this to also wash their feathers.
Birds don't need to puff themselves up to scare away predators, they have wings which allow them to fly away.
to make themselves look larger and possibly scare off any predators. And they sometimes do it to get water off their feathers
To make themselves look bigger to scare away predators