For them, sleeping like this is as comfortable and natural as bed for us.
In order to be safe on the branch, a bird should only bend its legs . Thus, its flexor muscles tighten the tendon of the fingers , which curve, securing the legs and claws around the branch. In this way they can fix themselves in a stable way while they sleep.
This same mechanism is what makes birds of prey effective hunters. With outstretched legs they throw themselves on the prey; impact carries the force necessary to flex your legs, which automatically extends to your heels.
When birds sleep on trees they need to camouflage themselves; some stay still to blend in with the branches. Thus they manage to survive against possible attacks.





