From "To sleep, perchance to dream . . ." to "I couldn't sleep a wind last night . . . ." sleeping has always gotten a good share of attention from poets songwriters, authors, painters and, naturally insomniacs.

There is the 17th-century Flemish painter Jan Vermeer's soporific painting of "A Girl Asleep." And there is the insomniac Lord Chancellor from Gilbert and Sullivan's "Iolanthe," whose short-term plaint is universal:

"When you're lying awake with a dismal headache/ and repose is taboo'd by anxiety/ I conceive you may use any language you choose to indulge in without impropriety/ For your brain is on fire -- the bed clothes conspire of usual slumber to plunder you/ First your counterpane goes, and uncovers your toes, and your sheet slips demurely from under you/ Then the blanketing tickles -- you feel like mixed pickles -- so terribly sharp is the pricking/ And you're hot, and you're cross, and you tumble and toss till there's nothing twixt you and the ticking . . ."

Clearly, W.S. Gilbert knew insomnia.

And some 95 years after his Lord Chancellor's first on-stage moan, there are plenty of people who can relate personally and painfully.

Most insomnia that is not part of some other illness or mood disorder is usually not long-lasting. Occasional bouts of insomnia of a few days' duration can be induced by all sorts of stress, but those few that last indefinitely, with no apparent cause, still resist therapy.

But until recently, beyond the "early to bed, early to rise . . ." aphorism, and the conventionally wise but not necessarily true notion that one quarter of a day should be spent in sleep by everyone, no one had really examined sleep scientifically -- what it is, why we need it, how it relates to mental and physical well-being.

In the past 10 or 15 years, sleep studies have burgeoned, along with new diagnostic imaging techniques, new knowledge about how the brain works, about how the daily body rhythms -- circadian or biological rhythms -- synchronize virtually all body functions and how the "clocks" of the body that control the rhythms are set.

None too soon, either, with an estimated annual average of 600 tons of purported sleep-inducers consumed by some 75 million Americans engaged in an endless and often fruitless search for a good night's sleep. Of these, about a third have a long-term sleep disorder that has serious effects on their daytime functioning.

None too soon, either, for unnumbered thousands who die in their sleep, because they have spent literally years with a disorder that makes them stop breathing for short intervals, sometimes hundreds of times during the night. Usually, between their non-breathing periods and their characteristic trumpeting snores, they wake up for moments so brief they do not remember and breathing resumes. Some, eventually, do not wake up. They succumb to apnea-induced strokes or heart attacks, brought on by years of nights spent in chronic oxygen deprivation, which can cause such problems as an enlarged heart. This is sleep apnea, often unsuspected, potentially fatal.

None too soon, either, for the people who are less worried about not sleeping a wink at night than they are about staying awake during the day. "The American Medical Association Better Sleep Book" dubs the syndrome a problem of "too sleepy people."

These might be people who simply did not get enough sleep the night before because they watched "Casablanca" one more time on the late late late late movie -- or those who make a habit of sleeping too little. Or people with sleep apnea, for which daytime sleepiness is a major clue to diagnosis. Or some even more bizarre disorders like narcolepsy in which people drop off to sleep even in the middle of making love or driving a car, or like cataplexy, a subtype of narcolepsy, in which people literally fall down asleep. Or, indeed, people with any disorder that deprives them of sleep at night.

Dr. David J. Kupfer, one of a handful of pioneers of sleep studies, now chairman of the department of psychiatry at the University of Pittsburgh and head of sleep studies at its affiliated Western Psychiatric Institute and Clinic, notes that sleep medicine has come of age, "but there is so much more we can still do. We don't have a lot of treatments for a lot of these disorders. We need more clinical trials, but we have become aware that you define somebody with a sleep disorder not by looking at how they are sleeping at night, but by defining how they are functioning in the day."

The man who sleeps only four hours a night but goes about his business normally the rest of the time does not have insomnia, Kupfer notes. But the man who sleeps seven hours and feels sleepy all day may well be an insomniac.

Kupfer sees sleep as "a great window into the central nervous system." On the other hand, he says, "you can't study just sleep by itself because there are too many things going on."

The average person spends almost a quarter of a million hours -- about a third of his life -- sleeping. The need to sleep is virtually irresistible, and people who have tried to stay awake for days on end have eventually experienced delusions and hallucinations. One of life's nicest feelings is giving in to the body's directive to sleep, lying in a warm bed, in blissful comfort, in those conscious moments before sleep takes over.

It was only in the early 1950s that scientists realized that sleep was not just a quiet state of rest, that there were different stages of sleep. They learned that one of those stages, the period when there were rapid eye movements (REM), was quite active -- at least mentally, at least as an electroencephalograph (EEG) registered it. The most vivid or best remembered dreams occur during REM sleep, and specialists can often diagnose specific disorders, especially forms of depression, by noting how soon a sleeper goes into REM sleep.

In normal sleep, REM occurs about 90 minutes after a person falls asleep. Sleep stages recur in approximately 90-minute cycles, with three quiet stages (light to deep slumber) at the beginning and REM towards the end.

During REM sleep the body is virtually paralyzed -- only the brain is working "actively," while in other so-called "quiet" stages a person may toss and turn and kick a leg or fling an arm, burrow under a blanket or curl into a ball -- averaging 30 such moves a night.

When either REM sleep or very deep sleep -- called "slow wave" or "delta" sleep -- is disturbed or fragmented, as it may be in some sleep disorders, or by some sleeping pills, or by alcohol, the body moves to make up for the lack as soon as possible. First the body tries to make up for the very deep slumber that was missed, and then for the missing REM sleep.

Kupfer believes that the importance of REM sleep may have been overemphasized in early studies, but inasmuch as sleep was defined until very recently in terms of sleep disorders, the actual functions of the various stages of sleep in the normally sleeping person have yet to be definitively described.

Sleep studies have turned up disorders people never even knew they had -- myoclonus, for one, in which the sleeper spends the night in periods of sharp kicks, unaware that his sleep has been disturbed, despite strong testimony from bedmates. Some of these victims experience a recurrent sensation in their legs when they are awake, requiring that they move -- perhaps walk around -- to relieve it. Some specialists believe that where there is this "restless leg syndrome," there is a sleep disorder.

Another disorder appears to be a kind of epilepsy that only shows up during sleep, registering on no neurological measures when the person is awake. However, it interferes with sleep, often causing severe daytime sleepiness, and can be controlled with certain anti-seizure medications.

Certain drugs also have been found useful for narcoleptics; tonsillectomies are often curative for children with sleep apnea; adult sleep apnea is treated with weight loss when possible, surgery and some new devices. When depressed patients are treated for their depressions, their sleep problems often become resolved as well.

Moreover, physicians are more attuned to prescribing sleeping pills only for short periods of time and only in certain circumstances. Total numbers of prescriptions for sleep medications peaked in 1971 with 42 million written, and declined gradually to 21 million in 1982. There have been small increases in 1983 and '84, although no final figures are available.

Dr. Wallace B. Mendelson, chief of sleep studies at the National Institute of Mental Health (NIMH), emphasizes that insomnia itself is "a complaint, not a disorder." Most patients who have trouble sleeping have one of a variety of other problems, physical or psychiatric, for which sleeplessness is a symptom.

However, there are some people who complain that they lie awake night after night after night. "Doctor," they will say, "I haven't slept in months."

This group, the "hard core," in whom no known disorder can account for their sleepless nights, is now the subject of some NIMH studies in which Mendelson and some of his colleagues believe they will be dealing with the uncharted areas that provide the interface between body and mind.

In studying these "pure" insomniacs, researchers have found several things. For one thing, said Mendelson, "When you awaken insomniacs from a stage of sleep measured in a sleep laboratory where the EEG tells you they are really asleep, they say they weren't asleep.

"We are beginning to think that may be the real essence of insomnia." These people believe themselves to be awake when all the objective measurements show they are asleep. In fact, they are asleep, certainly for longer periods than they believe.

Moreover, he said: "We've just finished some work to show that poor sleep is not the same as light sleep. In other words, common sense might tell you that people who say they are insomniacs are disturbed more easily by noise than are others. It turns out that is not really true. We did a study where we had a noisemaker in the room and tested how much noise it took to wake up insomniacs. We found they were no different from others. There are also light sleepers, of course, but being an insomniac doesn't mean that your problem is that you are sleeping so lightly that noise disturbs you."

Nor do these insomniacs sleep better in the daytime.

"It turns out," said Mendelson, "these insomniacs complain how tired they are, but new studies show that if you actually measure their tendency to sleep in daytime, they don't go to sleep any more quickly than normal people."

"This is not to discount their pain and discomfort, but it is not sleepiness. It is feeling rotten, and many of them perceive it as sleepiness, but if you actually give them an opportunity to sleep, they have the same trouble sleeping in daytime as nighttime."

"The other thing we found," Mendelson said, "after reviewing several hundred studies on the effectiveness of hynotic drugs [sleeping pills], we found that the average increase of sleep time of all the studies combined was about 30 minutes.

"I can't believe that that 30 minutes really does the job. Nevertheless, these [insomniac] people swear by these medicines, and the degree of help that people feel they get seems to be very out of proportion to that 30-minute figure.

"What that makes me think is that insomnia is a dissociation between objective measures of sleep -- the EEG -- and your subjective response or impression as to your state of consciousness." Mendelson hypothesizes that "maybe what sleeping pills do is realign those two so your subjective feeling matches the objective measurement." In other words, the insomniac believes he has slept more thanks to the pills, even though he hasn't.

NIMH is also studying the possibility that the natural hormone melatonin may be a useful sleep agent. "No one knows if [melatonin] will help insomnia," Mendelson said, "but there are several reasons why some researchers think it might. In the first place it is a hormone secreted while you sleep. Nobody really knows exactly what it does, but some studies indicate it may have some sedative properties.

"There is also some speculation that it is related to coordinating things in the body, letting internal organs know, for example, that it is nighttime, sort of keeping the body clocks synchronized."

"It is known that when it is secreted, it bathes both the brain and the body."

Mendelson's hypothesis is that melatonin normally serves to synchronize the body's various circadian and biological rhythms. He speculates that melatonin "is a way of transmitting information about the outside world to the inside of your body, one of the interfaces of biology and behavior.

"How does some piece of whatever tissue you want -- kidney or liver or whatever -- know whether it is day or night? They don't have eyes." Yet many organs function differently at night, or at least during sleep, than they do during the day.

According to Pittsburgh's David Kupfer, it is the onset of sleep, rather than the onset of night, or darkness, that is the most powerful trigger -- or zeitgaber (light cue) -- for a whole spectrum of neuroendocrine activities and biological cycles that kick in during sleep.

"We think that if we understand what goes on normally, then compare that to what goes on in depression or other psychiatric states," he said recently, "we would have a very nice set of keys to get into the house and find out what is going on upstairs."

Research on sleep may proceed along another new line of inquiry with the discovery in the past year of a genetic marker for narcolepsy -- found first in a Japanese sleep center, but now replicated by many other researchers. Familial or genetic elements can help in early identification of high-risk members of a family with a propensity to depression or other mood disorders or narcolepsy who might then be helped.

With all, specialists are still not really sure what a prolonged lack of sleep will do, or even how much sleep anyone ought to have. Or, for that matter, why we sleep at all. The "right" amount of sleep varies widely from person to person, the average being about 7 1/4 hours a night. Some people do well on five. Some yawn all day after 10. As to what the fallout of lack of sleep might be, "We really do not know the price we pay over a lifetime," Mendelson said.

"Only now," said Kupfer, "are we beginning to look at normal sleep, starting from age zero to age 90. I think a lot of mythology will be dissolved. For one thing, the idea that old people sleep less. If you look at sleep patterns over 24 hours, you will see old people nap a lot. They aren't sleeping that much less at all."

All-day sleep studies of normal people -- infants, children, adolescents on up through old age -- "may give hints in successful aging," Kupfer said. "An easy hypothesis is that if we maintain certain levels of sleep and a certain quality of sleep, that may represent successful biology as we age, and it may have certain protective qualities and may be a predictor of longevity." More Information

For information on NIMH sleep studies on insomnia perceptions or on the usefulness of melatonin, phone 496-1056. Write: Sleep Studies, National Institute of Mental Health, National Institutes of Health, Bethesda, Md. 20892.