You forget how hard it is to stand up. As a two-legged mammal you're no more fundamentally stable than a bicycle made of beef - and it's only with constant muscular effort, and continuous lightning-fast readjustment of where our centre of mass is, that we manage to stay upright at all.

But that's okay for us, because at the end of a long day of standing, walking, and doing other human things, we can curl up in bed and take away all the strain that gravity has plagued us with since we woke up.

If you're a sweet little insect-eating bird, however, life isn't so easy. You've been struggling through the air all day, flapping from branch to branch to find very well-hidden grub, all the while avoiding being eaten by pointier, more carnivorous birds.

Making it back to your branch at night launches a final cruel challenge at you: If you curl up to sleep like a human, you'll fall to the ground, to the foxes and rats. You're going to need to somehow stay attached to the branch, even while you sleep.

So how do birds stay on their branch without being awake enough to balance? The first answer that springs to mind is simply "just keep squeezing hard and sleep!"

But after a quick think about what this would be like, it's clearly not a good answer. It's exactly like telling a person to keep standing while they sleep: Keeping any muscle contracted for so long is at the very least inefficient, and probably very uncomfortable. Just try standing up for eight hours.

"But horses can do it!"

That's right, conveniently placed reply, they do! But not by keeping any muscles contracted - horses have a special locking mechanism in each of their legs which, while engaged, essentially turns them into a completely rigid horse-shaped table.

Which is fine if you're on the ground and have four legs. But the zebra finch above definitely shouldn't try this party trick out. As branches come in different sizes, whatever size this hypothetically transplanted mechanism locked out at, it would almost never be quite right for him, and who wants to fly around for hours looking for just the right branch to sleep on?

What's more, even when he finally found one that seemed right, if the wind blew in the night, things wouldn't go so well for him. After briefly being the world's softest but least useful pendulum, he'd end up hanging upside-down from his branch. Not a good look, or sleeping position.

(Unless you're a hanging parrot, who seem to have evolved to do this, for reasons which are presumably as unclear to her as they are to us:)

A hanging parrot, as photographed by Raj Dhage. He takes incredibly dramatic and characterful photos of animals around Wai, India. Click here for so many more stunning pictures.

The solution perching birds have evolved is even more elegant than the horse's bone-locks. In the guise of an ingenious, and unfeasibly simple, internal pulley system, the birds have a self-correcting foot tightener. It's controlled directly by how bent their knees are, and is all made possible by a single well-placed tendon.

You might have noticed that birds' leg bones are sort of screwy, and have two joints instead of just a knee like we're used to. It's why birds seem to walk so weirdly, as their 'knees' look like they bend the wrong way, but are in fact not knees. The full story is fascinating, but probably best for another time.

On the right is the same view but simplified, showing how each leg bone rotates in each joint, and how the vital tendon is attached at one end to the knee, and at the other end to each of three claws. In between these two attachment points it's free to slide along its length. Importantly, tendons are not stretchy - pulling one is sort of like pulling a cord of leather.

So here's what happens as a bird lands, and gradually bends its leg:

As the leg bends progressively, the second, lower joint swivels round, forcing the tendon to cover a longer distance (as shown in red).

Starting slightly slack when the leg is fully extended, the tendon quickly gets taut, and as it's forced tighter and tighter, it pulls the toes inwards around the twig they're trying to land on.

For birds living amongst the branches with the characteristic "Three toes forward, one toe back" arrangement so good for gripping round things, this tendon works as an auto-perch mechanism. When they're about to land, or are taking off, their legs are extended, so the tendon's slack and their toes open out:

But once the bird's landed and bent his knees, the tendon, passed around a greater distance of that second joint, is pulled taut and closes the toes.

Now, the lucky bird can stay attached to the branch with almost no muscular effort. Some small amount must be necessary, and as we don't really understand much about how birds sleep, it's not impossible that some supervision by the brain is involved overnight.

Either way, this talon-tightening trick is a big help for staying in that tree once the sun's gone down.

It's also pretty good for those pointy predatory birds doing their best to ruin small animals' days: At the end of a dive, making claw-contact with their target makes their outstretched legs buckle, automatically closing their talons before they've had a chance to get distracted or miss their shot.

So the next time you see a little bird hopping around in a tree at sunset, remember (perhaps with a twinge of jealousy) that he'll be just fine sleeping on his feet that night.