With more than 3 billion people hopping on and off flights every year, it is inevitable that people die while flying.

However unpleasant the subject may be, it's a reality numerous cabin crew, pilots, and passengers face every year.

"Considering the sheer volume of people who fly every day and the growing number of elderly people who fly, I'm surprised it doesn't actually happen more often," commercial airline pilot Patrick Smith told Business Insider.

How the crew reacts to the situation and the procedures they follow vary based on the events leading up to the death. Policies can also vary by company.

"Protocols vary airline to airline," Smith said. "Decisions such as whether the flight should divert are handled on a case-to-case basis."

Generally, the flight crew and ground control will work together to come up with a plan of action that's tailored to each specific situation.

According to Smith, author of the book "Cockpit Confidential," some of the factors that can affect whether a flight diverts include the location of the flight, the events leading up to the passenger's death — i.e., whether there was a medical emergency — and what options are available to the crew.

In cases where there is a medical emergency, some airlines allow flight attendants to communicate directly with medical professionals on the ground while others require ground communication to run through the pilots.

Once the passenger is determined to have died, the cabin crew will first work to store the body in a respectful manner and, if possible, away from other passengers. If there is room, the body will likely be placed in unoccupied rows of seats or in first class where there is more empty space.

Some airlines allow their cabin crews to cover and place the deceased passenger on the floor of the galley at the back of the plane.

But on crowded flights, there may not be room to relocate the deceased, at which point the corpse would be covered up and strapped into a seat.

In 2004, Singapore Airlines launched its fleet of Airbus A340-500 airliners with a small compartment at the back of the plane near the exit doors. This compartment, large enough to store an average-size body, has become known as the "corpse cupboard."

At the time of the A340-500's launch, an airline representative told the Guardian's Andrew Clark that the compartment allows the crew to store a deceased passenger in a dignified manner and would be deployed only if an empty row of seats were not available.

Singapore Airlines retired its A340-500 fleet in 2013. It is unclear if any of the airline's other aircraft are equipped with this compartment.