I have been doing bird photography since last 7-8 months and as part of the excursions have been observing the birds seating on the branches, holding it firmly. In fact some of the birds like Woodpeckers are able to hold onto even the tree bark perfectly
During this time, have also seen various bird nests. Most nests are on the trees but some were also on the ground (yes, that's true.. and it is mostly without any protection). They are made even by digging dip into a soft muddy wall.
But one interesting fact I had overlooked was, “birds never use their nests for night-rest”, the only purpose the nests are used is for incubating the eggs and raising the chicks.
That brings us to the interesting question, where do they sleep at night (talking about the normal birds that are active during the day, the nocturnal ones will have exactly opposite cycle)? OR do they sleep at all? Not many would have actually seen a slipping bird, have you?
Naturally any living being will need rest, so do the birds. And they spend their night mostly on the tree branches. That’s where the question “why do they not lose the grip while sleeping?”.
If you try to hold onto something at the time of going to sleep (e.g. your mobile phone), it is bound to fall from your grip, once you get into deep sleep. When we hold something, we have to tighten some of our muscles (which means there is some energy spent by the body for the task). In fact, if you try to hold onto anything, there is a limit beyond which you will not be able to hold it (beyond that, your muscles will give up). If this is the case, then how do the birds do it?
As we know the birds were evolved from the reptiles millions of years ago and as part of the evolution the need to stay (or roost as it is correctly called) on the tree branches became necessity. And that resulted in their specific adaptation through evolution.
Check the diagram below:
It can be seen here that as the birds land on the tree, they fold their legs to get to a seating position and the moment they fold their legs, their feet will automatically grasp the branch.
Their bones/muscles/joints are structured in such a way, that by bending the ankle and knee joins, the grip becomes automatic, they do not have to exert any pressure for that. In fact, if they have to release this grip, they will have to force movement (straighten their knee and ankle joints)
This way they can continue to hold onto the branch for as long as they wish (without putting any undue pressure on their muscles) and that is the reason why they cannot fall from tree even while sleeping.