Meaning:
Counting sheep is a distraction technique used to help people get to sleep.
The mental distraction of imagining a field of sheep and counting them is
intended to distract insomniacs from fretting about being awake and relax
into sleep.
Background:
Insomnia has probably always been with us, likewise sheep. The counting sheep
technique, like other distraction exercises, is effective for some people who
find it difficult to get to sleep.
We have evidence of this particular technique, of counting sheep as they are
imagined in a field or jumping a fence, being used from at least 1854.
That's from Seba Smith's Way down East; or Portraitures of Yankee life:
"He shut his eyes with all his might, and tried to think of sheep jumping
over a wall."
- www.phrases.org.uk [edited]
-------------------------------------------------------------------------------
I've never tried and don't know how much counting sheep speeds up the trip to
the land of Nod. The English might not think twice but I'd be wondering about
the verdant pasture, the breed of the animal, what they are raised for, their
diet and temperament, Jesus carrying a lamb, etc. So I doubt the effectiveness
of this method.