It was less than an hour into Ryanair flight FR7033 when John Duffy noticed the man. Duffy, a 37-year-old IT worker, was flying home to Dublin from Faro in January this year when he got up to go to the toilet. As he walked down the aisle, he saw that a passenger a few rows in front looked unwell. "He had his hands up around his neck. I was standing in the aisle waiting and had a bird's-eye view of what happened: it was as if someone pulled the plug. He just collapsed and his head hit the back of the seat. The air hostess standing next to me picked up the phone and said, 'We've got a situation.' "

Lena Pettersson was going on holiday to Tanzania last year, a 10-hour Kenya Airways flight from her native Sweden. She and her travelling companion were sitting at the back of the plane. On the far side of the same row, they noticed a man who, even before takeoff, was clearly in a bad way. "He was sweating and the crew were all around him," Pettersson says. "They were coming and going with water, and he was not looking well at all. We took off and five minutes after that he became worse, had cramps and a really big problem. They asked if there was a doctor on the plane, and six came forward."

Shortly after that, the man collapsed. Cabin crew laid him in the aisle and the doctors continued to work on him for an hour. "We were flying over Europe," Pettersson says. "They could have come down anywhere. But they just went on flying. And then suddenly one of the doctors made the sign of the cross and started to pray. And I said, 'Oh my God, this is not possible. It's not possible.' "

The number of people travelling by air is rising. According to the International Air Transport Association, the volume of passengers taking commercial flights each year will reach 3.3 billion worldwide by 2014, up 30% on five years ago. Of those, roughly 800 million will fly in Europe, a quarter of them in the UK. The Federal Aviation Administration believes that by 2034, more than a billion passengers will fly per year in the US alone.

So it is perhaps unsurprising that, every other week in the US, there is a news story about someone dying in the air of natural causes. (For it to make international news, there has to be some extra element, such as the pilot dying, or a fellow passenger suing the airline for compensation.) Events and behaviours considered unremarkable on the ground have extra weight in-flight, tapping into our deep, atavistic insecurities about flying and exacerbated by a simple fact: as Patrick Smith, a commercial airline pilot and author of Cockpit Confidential, puts it, "People just get weird around planes."

Bangor airport serves an area in Maine with a population of 35,000. It has no scheduled international flights and mainly caters to short domestic runs around the American north-east. Nonetheless, it has an international terminal with four gates, a $700,000 towing vehicle capable of moving the Airbus A380 superjet – the world's largest passenger plane – and immigration officials permanently on stand-by. After flights leave the coast of Ireland, it is the first port of call on the transatlantic route; in the past 10 years, it has received more than 600 diverted flights, usually because of fuel emergencies. (In strong headwinds, planes burn more fuel and may hit the coast of America with the needle on empty.) It is also a landing option for flight crews dealing with medical emergencies over the Atlantic. As Eugene Foren, the chief dispatcher at the airport, told the Wall Street Journal last year, "This job is 98% boredom and 2% sheer terror."

"You have to think of the flying population as a virtual city. At any given moment, there are around 600,000 people flying. If you keep that city flying for 12 hours, some people will die."

A few months ago, Tobias Morter was doing the drinks service on a transatlantic flight out of London. At 19, he is the youngest member of staff on a British carrier that transports millions of passengers around the world each year. A passenger got up from his seat and Morter leaned back to let him pass. "As I was moving, he fell on the floor. He was having a fit. It was a good job it happened out there and not in the loo." A call was put out for a doctor on board. ("You have to say 'doctor of medicine'," Morter says, "or else you get all sorts of people coming up.") As flight crew performed chest compressions and someone ran for the defibrillator, a decision was made to divert to Bangor. At the same time, from the flight deck, a call was put in to the emergency services – in this case MedAire, a company that provides 120 airlines with on-the-ground medical support.

The MedAire dispatch centre is in a hospital emergency room in Phoenix, Arizona, where calls from flight decks around the world are put through to serving doctors. It is a phenomenally difficult job: to talk a flight attendant trained in first aid through a medical emergency and, based on the information, advise the pilot whether or not to divert. As Heidi MacFarlane, vice-president of the company's strategic development, says, "It's like stepping into any other treatment room in the ER, except blindfold and with their hands tied."

The whole business of "Is there a doctor on board?" is one about which MedAire and companies like it are deeply ambivalent. Dr Paulo Alves, a cardiologist and former airline medical director who is now vice-president of aviation health for MedAire, would rather talk directly to cabin crew than to the unknown quantity of a volunteer. "Don't get me wrong – we're extremely grateful to volunteer medical people," he says. "But a medical person on the flight is primarily another passenger. We don't know anything about his or her background training, we don't what condition they're in. Were they drinking? Did someone just wake them up? How fit they are to provide a sound medical judgment isn't known. MedAire alleviates the pressure on that volunteer."

It also takes the pressure off cabin crew who, given the cost and inconvenience, may be reluctant to recommend that the plane land. (Most airlines will move heaven and earth to avoid a diversion.) Only about 2% of MedAire's emergency calls result in diversions and a fraction of that number in the death of a passenger. "You have to think of the flying population as a virtual city," Alves says. "So at any given moment, there are around 600,000 people flying. If you keep that city flying for 12 hours, some people will die."

"The biggest problem when a passenger dies is where to put them. On a full flight, there isn't space. There were a couple of times when people were placed in a lavatory, rigor mortis set in and they couldn't get them out."

In his 20 years in the business, Richard Havers had mercifully few onboard medical emergencies and just one in-flight passenger death – on a Continental Airlines flight from Gatwick to Houston, diverting to Bangor, by which time the passenger was already dead. Havers, the author of Airline Confidential, was Continental's vice-president for Europe and well versed in the kinds of hair-raising stories that circulate around the industry. "The biggest problem," he says, "and this is slightly disturbing, is that when a passenger dies, it's a question of where to put them on the aircraft. They have to find a quiet place, but on a full flight, there isn't space. That creates a problem. And there were a couple of times when people were placed in a lavatory, rigor mortis set in and they couldn't get them out."

"Unfortunately, most flights are full," says Heather Poole, a flight attendant for a major US carrier and author of Cruising Attitude, an account of her experiences in the air. "So it's not always possible to move an incapacitated passenger to an empty row of seats. Singapore Airlines is the most prepared. Some of their planes feature a 'corpse cupboard', a compartment for storing a dead body if the situation arises."

Kenya Airways does not have this provision, as Pettersson discovered first-hand on her flight to Dar es Salaam. After cabin crew asked passengers sitting in the middle of her row to move, they put a blanket over the dead man's head and laid his body across three seats.

"But he was quite a tall man," Pettersson says, "so his feet were sticking out into the aisle, pretty close to me. I asked if maybe I could move. And they said, no, there were no other seats." She travelled like this for nine hours. "I felt very, very sorry for this man." But she also felt uncomfortable sitting next to a corpse, and was ultimately given a refund. (Kenya Airways never revealed the man's identity or cause of death, but when Pettersson spoke to one of the doctors who had tried to save him, "she thought he was probably a drug addict or dealer and had swallowed something in a plastic bag that had broken inside his stomach. That was her theory.")

Like train drivers traumatised when someone throws themselves on to the tracks, cabin crew can be damaged by these kinds of onboard emergencies. At Morter's airline, staff are offered four or five counselling sessions, although he says there's a general lack of empathy from management. This is best illustrated by the number of people turning up on the manifest with a "conditions of carriage" note beside their name. Effectively an airline-issued asbo, this should ban them from flying for non-medical reasons – but there they are, in the air again.

When a passenger falls ill, Morter says, the biggest problem is usually their family. "If the family is hysterical, they're the ones you need to control more than anyone else." After mechanical or security problems, the biggest challenge is managing potential passenger panic. Someone dying on board shouldn't rattle passengers elsewhere on the plane; it's not contagious. But one feels more vulnerable in-flight, strapped in and with nowhere to go.

"We took off out of New York and had to come back because a passenger was sick, and we ended up having to jettison I don't know how many thousands of pounds of fuel, because we couldn't land overweight.

Patrick Smith, who has been flying commercial passenger planes for 20 years, takes a dim view of some passenger psychology. "Some people are legitimately ill and it's a serious concern," he says, "but sometimes I think passengers who are ill don't always realise what a big deal it is to divert a plane, especially on an international flight. It's not like a bus, where you can just pull over and drop the person off. It can wind up costing hundreds of thousands of dollars."

Is it alarming for a pilot, to have to divert?

"Yeah, it's a lot of work. The worst-case scenario is you're over the polar region somewhere, or in the middle of the ocean, and have to divert to one of your pre-planned diversion airports. The logistics are challenging."

All long-haul flights have divert airports written into the flight plan, but depending on how far into the flight the emergency happens, pilots can have a tough time landing. "Sometimes a divert entails jettisoning fuel, which is extremely expensive and time-consuming," Smith says. "I had a case about six months ago where we took off out of New York and had to come back because a passenger was sick, and we ended up having to jettison I don't know how many thousands of pounds of fuel, because we couldn't land overweight. That took the better part of an hour. Then that became a maintenance issue and the plane had to undergo an inspection before it could fly again. All because one person decided he wanted to get off."

Of course, without knowing it, most of us have flown on planes with dead bodies, which are being repatriated, in the hold. (Pilots, Smith says, are generally informed only if it's a VIP.) Passengers who die in-flight, meanwhile, are not technically dead until pronounced so by a doctor or coroner: "So no one ever actually dies on an aircraft," says Havers, who avoided the topic in Airline Confidential; it was intended for in-flight reading and he didn't want to unnerve his readers. Soothing nervous flyers is something airlines have approached in varying ways over the years. When Havers started out in the airline industry in 1969, on a defunct carrier called British United Airways, cabin crew in the UK were exclusively hired from debutante circles. Havers laughs. "And when airlines first started – this may be apocryphal, but I don't think it is – most of the people they employed as stewards were actually nurses."

Even today, with low-cost carriers undermining the mystique of air travel, there is still something vaguely magical about flight crew, these people to whom one looks for reassurance in the event of scary turbulence. Post-9/11, they are trained to be cautious even in the face of a medical emergency. "You want to be there for that passenger, but you never know if it's a decoy," Morter says. "There might be a passenger pretending to have a fit and someone trying to get into the flight deck at the same time."

Or, Poole says, it may be the case that the passenger has merely taken a sleeping pill and passed out. ("I'll never forget that lady. We checked for breathing. Checked for a pulse. Cleared a row of passengers and were just about to get her body flat on the ground when she came to. Turned out she'd taken a sleeping pill. That's why we prefer passengers to take them after we've pushed away from the gate and we're up in the air, in case there's a delay and we have to disembark. Flight attendants can do a lot of things, but there's no way we're going to be able to drag half a plane full of disoriented wet noodles by the ankles off the plane.")

On long-haul flights, one of the most common emergency calls relates to what looks like gastroenteritis: it could be a bug, food poisoning, or the prelude to a heart attack

For the doctors at MedAire, the most common emergencies are often the trickiest. Fainting is particularly difficult to deal with remotely, MacFarlane says, "because it looks as if the person is dying. As soon as someone loses consciousness, it goes to a different level in everyone's mind. It looks really bad. Same thing with seizures. It presents very poorly."

On long-haul flights, one of the most common emergency calls relates to what looks like gastroenteritis. This, too, is difficult to diagnose from the ground: it could be a bug, food poisoning, or the prelude to a heart attack. The usual rules of medical practice are inverted: on the ground, treat the cause, not the symptom; in-flight, treat the symptom just to buy enough time to get the sufferer safely to the ground.

Once the aircraft landed in Bangor, the man who fell ill on Morter's flight recovered. (One of the services offered by MedAire is dealing with the bureaucratic headache on the ground prior to a diverted plane landing. "You come with an ill person, and they need to be cleared by drug enforcement, or the health authorities," Alves says. Or immigration, all of which can impede a passenger's progress to hospital.)

Last January, as the Ryanair plane flew over the south coast of Britain, John Duffy helped the crew lift and carry the sick man up the aisle to the front, where he was laid on the floor. Passengers were told the plane would be diverting to Bristol. A short while later, they were told that, actually, it was going on to Dublin as planned. "It was clear that he was dead," Duffy says. "His face was completely purple. And the doctors had tried CPR. He was on the floor, still at the front of the plane. The doctor who was two rows in front of me said, 'He'll be tended to when he gets into Dublin.' He obviously didn't want passengers to hear there was a dead body on board."

After landing in Dublin, passengers were asked to exit through the rear of the aircraft. The man's wife, Duffy says, was in a state of shock, but there were no hysterics. While they were still trying to save her husband's life, the doctor had come over and whispered something inaudible in her ear, to which Duffy had heard her reply, with dreadful quietude and in echo of the flight attendant's general consolation: "These things happen."