The horses manage to sleep standing up thanks to the particular nature of their ligaments, useful for maintaining control of the limbs with minimum effort. In particular, the muscle bands present in the legs are structured so as to balance the movements of the joints, allowing them to support the weight of the animal and keeping it in balance even during sleep.
They do not always sleep standing up. This does not mean that all horses always sleep standing up. The mechanism described above, in fact, works only in states of "light sleep" (defined as "short brain waves"), whereas when equines reach the REM phase they need, just like us, to lie down … This is because deep sleep lacks their muscles of the tone necessary to maintain the standing position.
Anatomy aside, the habit of sleeping standing up, common to many herbivores, is also a matter of survival . In the event that any sign of danger aroused from rest, the horse would in fact be able to gallop within just two seconds.