Budgerigars—also referred to as budgies, parakeets and just plain keets—are miniature replicas of their larger cousins, the parrots, and the whole lot belongs to a group called "perching" birds because they have flexible feet that can wrap around and hold on to a skinny branch or a wire.
Put Your Little Foot
Even better, parakeets have zygodactyl feet, which gives them what amounts to opposable thumbs. Their four toes are arranged so that, if you label them like your fingers (leaving out the pinky), the thumb and ring finger reach backward and the pointing and saluting fingers stretch forward. This gives them a good grasp of things, from their perch to big chunks of food for nibbling.
The third factor that lets parakeets sleep on a perch and not fall off is a tendon in their legs that locks in place when the bird hunkers down to sleep. The flexor tendon runs from the bend in the middle of the leg that looks like a knee turned backwards, but actually corresponds to the heel of the human foot, to the tips of the toes. It releases automatically when the bird stands up.
A Leg Up
Even if your parakeet sleeps on one foot, she still won't fall off. She may sit on one foot to rest the other, to help minimize heat loss from the featherless legs if she's chilly or just because she feels safe and secure in the environment you provide.
The World Turned Upside Down
The same system of flexible feet, grasping toes and locking tendons keeps your parakeet firmly attached to her perch if she's upside down. Birds will sometimes sleep that way out of instinct—in the wild, the underside of a high branch is protected from airborne attack by the branch itself and is concealed from the ground or lower branches by the leaves.