I'm going to start this by saying beating a horse is never right. It is not just cruel - it's counterproductive. Excessive use of the whip may get an immediate response at that moment, but I have never in my life seen it fix the underlying problem. I once worked with a trainer who believed in beating horses that were spooking to make them "more afraid of you than whatever they were afraid of." Most of the horses she tried this tactic on got spookier. She never changed it, though.
That said, you will often see horsemen carrying a whip. I'll talk about different kinds of whip later, but the plain truth is this:
Even the smallest horse outweighs even the largest handler by at least twice (with the possible exception of some of the very small minis). These are big, dangerous animals - and sometimes the whip has to be carried and used.
A whip is used in three ways: Reinforcement, discipline, and signaling.
1. Reinforcement is backing up a cue the horse is ignoring, normally a cue to move forward. Some horses are naturally lazy and horses used for training beginners get very "numb" to leg aids. And, of course, you always carry a whip when driving as the only other forward signal you have is your voice. On a riding horse, the whip is used lightly right behind the leg that is being ignored, normally on the inside when traveling in a circle. If the horse is being particularly stubborn, you may hit them a little bit harder. When driving, the lash is touched lightly to the hindquarters. The whip is never used hard for reinforcement and it's really the equivalent of "raising your voice" to the horse (remember that to horses visual and tactile contact is part of their language).
2. Discipline. Yes. Sometimes you need to hit a horse that's misbehaving. Once. Immediately after the misbehavior. Horses are traditionally stated not to understand delayed consequences - but it's more that they get confused about what they're being told off for. However, only a skilled horseman should be using the whip in this manner - one who can tell the difference between a misbehavior out of "evasion" - that is a desire to get out of work - and one that's coming out of fear or pain. You also need to know the personality of the horse. I know one horse who's ass I kicked a few times who now whickers whenever I show up, but I've worked with others I wouldn't dare touch with a whip even once because they'd just melt down. And, again, you don't beat the horse - you don't hit them multiple times per incident, you don't hit them as hard as you physically can. You only hit a horse on or around the head if it just bit you and then never with a whip or device - only your open hand.
3. Signaling. Signaling is using the whip to give the horse an instruction. If you go on Youtube and look at videos of people lunging horses, you will see the whip pointed to the quarters for go faster, to the shoulder for slow down. Show jumpers will sometimes tap a horse lightly on the shoulder to remind them to pick their hooves up and try not to hit the jump. The use of a whip at the end of a horse race is primarily a signaling thing - a lot of the time the jockey waves the whip around a lot and barely if ever touches the horse with it, basically reminding the animal that the race is nearly over and he should be putting in all of his effort now. Watch any circus involving animals and you'll see the use of the whip as a signaling device in its highest form.