Counting sheep is a mental exercise used in some cultures as a means of putting oneself to sleep. In most depictions of the activity, the practitioner envisions an endless series of identical white sheep jumping over a fence, while counting them as they do so. The idea, presumably, is to induce boredom while occupying the mind with something simple,, and rhythmic, all of which are known to help humans sleep. Although the practice is largely a stereotype, and rarely used as a solution for insomnia, it has been so commonly referenced by cartoons, comic strips, and other mass media, that it has become deeply engrained into popular culture's notion of sleep. The term "counting sheep" has entered the English language as an idiomatic term for insomnia. Sheep themselves have become associated with sleep, or lack thereof. The effectiveness of the method may depend upon the mental power required. An conducted by researchers at Oxford University, though not involving livestock as the object of visualization, found that subjects who imagined "a beach or a waterfall" were forced to expend more mental energy, and fell asleep faster, than those asked to "simply distract from thoughts, worries and concerns." Sleep could be achieved by any number of complex activities that expend mental energy. An early reference to counting sheep as a means of attaining sleep can be found in Illustrations of Political Economy by Harriet Martineau, from 1832:
"It was a sight of monotony to behold one sheep after another follow the adventurous one, each in turn placing its fore-feet on the breach in the fence, bringing up its hind legs after it, looking around for an instant from the summit, and then making the plunge into the dry ditch, tufted with locks of wool. The process might have been more composing if the field might have been another man's property, or if the flock had been making its way out instead of in; but the recollection of the scene of transit served to send the landowner to sleep more than once, when occurring at the end of the train of anxious thoughts which had kept him awake."
An even earlier reference can be found in "Don Quixote" by Miguel de Cervantes, from 1605 :
"Let your worship keep count of the goats the fisherman is taking across, for if one escapes the memory there will be an end of the story, and it will be impossible to tell another word of it."
Cervantes probably adapted the story of counting goats from a story of counting sheep in the early twelfth-century Spanish work Disciplina Clericalis. The section The King and his Story-teller uses the idea of counting sheep humorously. Disciplina Clericalis draws mainly on literary sources from the Islamic world. Counting sheep was probably a widely recognized practice in the Islamic world before the early twelfth century.
, an American mattress manufacturer, uses animated sheep characters in its "Counting Sheep" advertising campaign, which it launched in 2000. The advertisements and characters were created by Aardman Animations. In Goodnight Mr. Bean, the thirteenth episode of the Mr. Bean television series, Mr. Bean has difficulty falling asleep. He tries sleeping in different positions, then watches a chess game on TV. As he nearly falls asleep, he becomes startled when the television channel cuts to a Bodyform advertisement via a star swipe featuring loud rock music. Finally, he takes out a picture of a flock of sheep and begins counting them, first with his finger and then, after losing count a few times, with the assistance of a calculator. When he sees the number of sheep on the calculator display, he finally falls asleep. After the closing credits, he rolls out of bed and falls onto the floor, ending the episode. In Shaun the Sheep Championsheeps, a 2012 series of sports-themed animated shorts, the "counting sheep" cliché is referenced in the episode entitled "Steeplechase". In the short, Shaun and his fellow sheep participate in the steeplechase event. Bitzer the dog, who is the referee, and the other sheep and farm animals, who are spectators, all fall asleep watching Shaun and the other sheep running around the track and jumping over the hurdles. The title of Philip K. Dick's science fiction novel, Do Androids Dream of Electric Sheep?, references this term.