When it comes to getting unruly livestock to toe the line, sheepdogs certainly know their stuff. And now scientists know how these incredible canines do it, with new research showing that they follow two surprisingly simple rules when herding animals.

For the study, Dr. Andrew King, a biosciences professor at Swansea University in the U.K., fastened GPS units to a flock of sheep and a sheepdog. Then data collected by the units were analyzed in order to develop a mathematical model of how the dogs did their herding.

"We had to think about what the dog could see to develop our model," King said in a written statement. "It basically sees white, fluffy things in front of it. If the dog sees gaps between the sheep, or the gaps are getting bigger, the dog needs to bring them together."

So what exactly are the rules?

The dog tended to gather the sheep when they were dispersed.

The dog directed the sheep forward when they were aggregated.

Voila!

And in addition to showing how the dogs did their herding, the model suggests that a single dog can handle a flock of more than 100 sheep.

"Other models don't appear to be able to herd really big groups--as soon as the number of individuals gets above 50 you start needing multiple shepherds or sheepdogs," study co-author Dr. Daniel Strömbom, a mathematician at Uppsala University in Sweden, said in the statement.

King said the new model may prove useful in fields other than farming. Other applications, he said, include controlling human crowds and guiding groups of robots sent on exploration missions.