Fixing appointments with the López family can be tricky. "Come round at midday," says David López, when I speak to him on the telephone. "If you are lucky we will all be awake."

They are not. David's brother Miguel Angel, aged 36, has to be roused from the prone position. Their father Julián is here, as is their cousin Nuria, who keeps house, and admits that she is also finding it hard to stay awake. "This place is getting to be like a hospital ward," says David as he squeezes his considerable bulk into a chair in their spacious but drab sitting room.

The family's long, narrow Madrid apartment is a tunnel of doziness. Even at midday only a dribble of daylight enters, adding to the sensation of semi-wakefulness. Our conversation is accompanied by a symphony of yawning, eye-rubbing, occasional drifts into semi-slumber and sudden jolts upright as David, Miguel Angel and Julián snap back – or simply panic that they may have missed something. They do not want to seem impolite.

This gloomy apartment, on a street off Madrid's small red-light district, is a house of sleep. It is a place of yawning, snoozing and snoring, of eye-rolling, swooning bouts of momentary cataplexy and of wildly vivid, violent dreams. It is also a laboratory for the future where the mysteries of narcolepsy and cataplexy, the twin demons of hundreds of thousands of people, may be revealed.

The López clan is the first-known example of an extended family of sufferers in the world. Rosa Peraita-Adrados, the Madrid doctor whose dogged detective work tracked down the disconnected branches of a unique family that was fractured by Spain's bloody civil war, believes they could help to find a cure for one of the most puzzling of conditions. Their genes have already provided some of the strongest clues yet about what might be causing this strange and incapacitating sleep disorder.

Doctors once thought of narcolepsy and cataplexy as separate illnesses. The former provokes irresistible bouts of sleep; the latter is a momentary muscular collapse provoked by sudden emotions or laughter. Now it is clear the two things usually go together. David admits to often nodding off halfway through a task. He is so afraid of dropping dishes that he hugs them closely to his chest and walks very slowly to the dinner table. "It is just the fear," his brother says. "I sometimes want to point this out, or make a joke or something, but that might be worse." Laughter, he points out, is one of their worst enemies, as it provokes bouts of cataplexy.

Narcolepsy and cataplexy were both first described in the 1880s – and even then the first case of the latter, discovered by German doctor Carl Westphal, was a family problem, shared by a mother and son. About one in 5,000 people are thought to suffer from a condition whose prevalence varies across the globe, with some 12,000 in Britain alone.

Living with the illness can be tough. Sufferers struggle to stay either awake or asleep for a sustained period of time. Luckily for me, the Lópezes are enjoying our chat. "The worst thing is boredom," explains David, who is 30 and, like his brother, is out of work. "If I am doing something I really like, or a project I am working at, then I can keep going for hours. The blood reaches your brain and keeps you going. But the moment you relax, the blood doesn't get there and off you go."

"Often you don't realise yourself what is happening," explains Miguel Angel. "Someone says: 'Hey, you are falling asleep.' And you say: 'No. No I am not.' But you are." "And then," adds their father, "it is goodbye and you are out."

Miguel Angel says that he has to tell any new friends about his condition immediately. "But if you want a girlfriend then you have to find someone who is not only going to listen to you but can also understand what you are talking about." One symptom, the violent dream, is a relationship-wrecker; Miguel Angel's are terrifyingly vivid. "I've seen him hurl the bedside table across the room," says David. "Or he is asleep shouting 'Fire! Fire!'" Once, Miguel Angel grabbed his girlfriend – now ex – by the throat in the middle of the night. "I was upset with her about something and, rather than have it out with an argument, I took it to bed with me," he says. "It must have been frightening."

David, meanwhile, suffers persecution dreams. "Above all what you feel is fear, panic and sometimes you even experience your own death. It is like starring in your own horror film." Julián's cousin Jesús – another of Peraita-Adrados's patients – battles with everything from monsters to gypsy gangs, thrashing his limbs around in action-packed fights. But not all the dreaming in the house is bad. Sometimes euphoria strikes instead. "I have found my father chuckling loudly to himself in his sleep," says David. "Sometimes I too have woken up laughing myself silly. It all depends on your mood."

“I can walk along the street asleep. You hear what’s going on, but your eyes are closed”: twin brothers David and Miguel Angel López. Photograph: Hannah Lucinda Smith for the Observer

Dreams are so lifelike that they play tricks on the memory and sensations of déjà vu – associated with extreme tiredness in non-narcoleptics – are common and intense. "You are convinced you have lived it before," says David. "In fact, you don't know what is real and what is not." Reality can be further scrambled by short episodes of microsleeps and automatic behaviour, when sufferers continue doing routine tasks even though they have actually fallen asleep for a few seconds. "I can walk along the street asleep," explains Julián. "You hear what is going on, but can't see because your eyes are closed. It lasts a few seconds and suddenly, bang! You wake up. Perhaps someone touches you, or your head starts falling and you wake up to recover your balance."

David and Miguel ANGEL'S mother knew she was marrying into a sleepy family. In the working-class Madrid barrio of Lavapiés, their great-aunt Teodora was known as la dormida – the sleeping one. On the other side of Madrid, Julián's twin brother, Andrés, recalls other members of the family who were famous for their doziness. "Our own mother, Rosa, could walk down the street asleep," he says. "I don't know how she avoided being run over."

Their grandfather Domingo had similar symptoms. Like many narcoleptics, however, Rosa and Teodora worked around their illness, keeping down jobs as cleaners. Andrés, now aged 63, has also held down jobs most of his life – though Peraita-Adrados thinks the night shifts he worked at one stage may have been the trigger for the symptoms of his illness to appear.

Teodora's daughter Josefina, another sufferer who Peraita-Adrados tracked down in the modest Madrid barrio of Entrevias, says her mother and aunts developed their own mechanisms for controlling the disease. "My mother would fall deeply asleep on the bus or the metro, but somehow always woke up just before her stop," she recalls. Teodora, Rosa and their sister Patro were known together as las bellas durmientes – the sleeping beauties – and, in their later years, the latter two could often be spotted snoozing together in the sunshine on a bench outside the barrio's church. "We would all be eating together and suddenly both would be sitting there dozing. I remember Aunt Patro falling into her food," Andrés tells me. "Yes," says his cousin Jesús. "Patro was the real number!"

"Our mother was always on the lookout for the illness in us when we were children," says Miguel Angel. But symptoms often do not appear, or become striking, until the late teens or early adulthood. The brothers first noticed theirs in their mid-20s, though David recalls suffering an intense version of a common schoolchild's problem – staying awake in class. "I swear I slept through half of them," he said.

"It starts with my mouth being blocked, and then I lose strength. I can’t walk. Either I stay still or I sit down": Andrés López-Bartoli. Photograph: Hannah Lucinda Smith for the Observer

Peraita-Adrados first became aware of the family history when Andrés was referred to the sleep disorder and epilepsy unit she runs at Madrid's Gregorio Marañón University Hospital. "The first time I saw Andrés," she says, "he told me he had a twin brother, Julián, who had been diagnosed in another hospital. And Julián's children had also been diagnosed, but no one had put them all together. That was when I realised this might be interesting. There had been very little studying of families, so I got into contact with Professor Mehdi Tafti at the Centre for Integrative Genomics at the University of Lausanne, and said, 'This is important, why don't we study it?'"

It took Peraita-Adrados years of trawling through records at various Madrid hospitals to trace the members of the clan and find their clinical histories. Different branches of the family went their own ways during the Spanish civil war in the 1930s, after they emerged from that conflict – like much of the militantly left-wing working class in Lavapiés – on the losing side. Rosa and her husband were both jailed after General Franco's right-wing nationalists took Madrid in 1939 and rounded up many of those who had defended the city or joined the communist, socialist or anarchist groups that had helped run the Spanish capital over the previous three years. The twins and their four other children were distributed around the family and spent periods of their childhood apart. Their father was a candidate for the firing squad, but ended up with a long prison sentence; Rosa got out of jail earlier and later had children with another man. Death and prison fractured the clan, leaving a plethora of half-siblings and a split Spanish family. "It is true there are a lot of us, but we hardly ever see them. Not aunties or cousins or anyone," explains David. "Not that I've ever felt the need. It has just always been like that."

Now a family tree starting with great-grandfather Domingo covers 48 people over four generations, with 14 members of the third and fourth generations showing symptoms of narcolepsy-catoplexy. Fewer than 10% of narcolepsy-cataplexy sufferers have relatives with the illness, and only 1 or 2% share it with more than one other person in their family. Certainly no family as extended as this has been available to study before, offering a unique opportunity to reveal some of the genetic secrets of the disease.

"There is evidence that the origin of the illness is autoimmune in the 95% cases which do not have an obvious genetic cause," explains Peraita-Adrados. Sufferers seem to produce antibodies that attack the hypocretin neurons, stopping or slowing production. Doctors can now extract spinal fluid and test for hypocretin to make a diagnosis. "If the levels are very low, or zero, you know that this individual will eventually have cataplexy," she explains. The few cases with a genetic origin that have been tested so far, like the López family, also show no hypocretin. "We found Andrés and Julían, the twins, had zero."

The discovery of the hypocretin deficiency a decade ago was key to understanding the mechanism behind the symptoms. Produced in the brain's hypothalamus, hypocretin (also known as orexin) plays an important role in a person's alertness. It also affects feelings of fullness, which explains why narcoleptics often develop strange eating patterns and may become obese.

Now the tests on the López clan provide clues about what may be going wrong at a genetic level. The most important discovery is a mutation on a gene known as MOG, which is shared by all sufferers in the family, but none who do not have the illness. This gene codes for a protein called myelin oligodendrocyte glycoprotein, which plays a key role in maintaining the central nervous system via an insulating material called myelin. The MOG gene has been linked to everything from schizophrenia and bipolar disorder to multiple sclerosis. Researchers are understandably excited by the discovery of a mutation in a family of people suffering narcolepsy with cataplexy. The task now is to try to find a link between myelin in the central nervous system and hypocretin deficiency. "What we are trying to do is complete the chain of the mechanism to work out how this mutation, which provokes a change in the myelin, connects to the part that we know about the symptoms and their mechanisms," says Peraita-Adrados.

Cataplexy generally, but not always, appears several years after the symptoms of narcolepsy are clear. It comes on suddenly, usually caused by a sudden surge of emotion. Sufferers lose muscle tone from their head downwards – jaw or neck muscles slacken, eyes begin to roll and finally legs start feeling weak and may buckle. "It starts with my mouth being blocked, and then I see that I am beginning to lose strength. I can't walk. Either I stay still or I sit down," explains Andrés, who was a first division football linesman and still holds down a weekend job as a referee. "It is as if I had gone out drinking and got totally plastered. Once it happened to me in the Puerta del Sol square and I remember people looking at me as if I was a stumbling drunk."

Jokes, his cousin Jesús explains, are another problem. Laughter, excitement, intense sadness or strong emotions of almost any kind can set him off. "Your neck feels weak and then your head just tips over." Even watching soccer matches can be tricky. "I can't celebrate Real Madrid's goals," he says. "Everyone else is jumping up and down and shouting, but I try to limit myself to just clenching my fists in celebration. If I screamed, I'd just fall over." Miguel Angel asks friends not to rag him. "They don't always remember. The other day we were helping a friend shift boxes of fire extinguishers and everyone started mucking around and having a laugh. Suddenly the cataplexy came on, so I had to stop."

Another common symptom is sleep paralysis, when they wake up, but cannot move or speak for up to two minutes. "Obviously your breathing muscles don't seize up, but the rest of your musculature is completely paralysed," explains Peraita-Adrados. "It produces huge anxiety."

“I remember Aunt Patro falling asleep into her food”: Josefina and her son David at home in Madrid. Photograph: Hannah Lucinda Smith for the Observer

Treatment is currently restricted to lifestyle changes or trying to block sleep and cataplexy attacks. "You don't cure the illness, you fight the symptoms," says Peraita-Adrados. American patients get amphetamines, while European doctors prescribe other stimulants. The new generation of Prozac-style anti-depressants help control cataplexy, though no one is sure why. Sodium oxybate, used in Europe for anaesthesia in the 1960s, is the only drug that improves nocturnal sleep and daytime symptoms. German investigators have begun to produce hypocretin – a key peptide that narcoleptics lack – and this holds out one hope for a cure, but it is still early days.

In another sleepy apartment on the other side of Madrid, Josefina struggles to get through stories about her children and grandchildren. The love she feels, and the waves of emotion her stories provoke, send her into brief bouts of cataplexy. Her 32-year-old son, also called David – who first noticed the symptoms while serving a drugs-related jail sentence – suffers from them, too. "If I get angry or argue with someone then my legs start to go," he says. "The last time was three days ago when I got angry with a guy on the bus and started telling him off."

Standing by Josefina's front door, as we say goodbye, we talk about pet dogs. "Mine died just three days ago, in David's arms," she says. The thought brings on a wave of sadness. Josefina's eyes roll over, her head tilts forward and she grabs for the doorframe, crumpling against it. Her cataplexy, explains Peraita-Adrados, is among the most severe – occasionally laying her out on the ground. Accidents happen. "I've burned myself a couple of times with cooking oil," Josefina admits. "I've seen her fall when she was doing the ironing, even when eating watermelon," says David.

Many sufferers manage to lead almost normal lives, holding down jobs, pursuing hobbies and raising children. Medicines, siestas and knowing their own limitations all help. The former head of the Spanish patient's association, for example, regularly drives 300 miles from Alicante to Madrid on his motorbike. Learning to repress emotions is one of the worst side-effects of the illness, says Peraita-Adrados. "Adults can have terrible lives. I've seen failed marriages and lots of people with problems at work. I had one patient who was a long-haul truck driver, doing journeys from Madrid to Amsterdam and, of course, he had an accident. He suffered with head injuries, but fortunately his life was saved." One member of the López clan had been a taxi driver.

"But the worst thing is the children," she says. "We are now seeing symptoms appear at a fairly early stage. These kids fall asleep in class and get called dozy-heads. They are fat, so they can't play. And then cataplexy starts to appear. They have to learn to control their emotions. They realise that when they are watching cartoons, for example, they can fall into cataplexy – and they just don't understand what is happening. I have a lovely little patient – the youngest I have ever seen – a girl called Natalia who is just six years old. She is an adorable, beautiful child. I asked her to draw me her dreams, so she did a lovely little drawing of her going over a bridge, but there was a monster there. I asked: 'And what is that?' And she said: 'Well, if I laugh I could fall and then the monster could come and attack me.' Her mother says she laughs less and less."

The genetic study may come too late to help the generation of Julián, Andrés and Josefina – but sufferers like Natalia will benefit if their extended family helps fill in the gaps in the chain of cause and effect. "If by studying us they can get close to finding a cure, then that would be fantastic," says Miguel Angel. "It would be great," agrees David. Their father does not join the chorus. He looks as if he is about to doze off on the sofa.