Passengers on a United Airlines flight from Newark to Glasgow, Scotland said they saw their pilot napping in the cabin during the flight.

Despite photos published in a Scottish newspaper going viral, this is actually standard practice - it's a federally-mandated safety measure.

Pilots on longer flights, including trans-Atlantic routes, are required to take a mid-flight rest period. On some larger planes, pilots have access to a separate rest area. On smaller aircraft, pilots rest in a reserved first class or business class seat.

On those flights, there's always at least one extra pilot on board so when one takes a rest, there are still always two pilots in the cockpit.

On a recent United Airlines flight to Glasgow, passengers were surprised to see one of the plane's pilots emerge from the cockpit, change clothes in the forward lavatory, and take a nap in an empty business class seat.

However, while this may have seemed unusual at first glance, it's actually common practice on commercial airlines - and it all has to do with ensuring in-flight safety.

Photos allegedly showing the napping pilot - taken by a passenger and published this weekend by the Daily Record, a Scottish tabloid - quickly went viral.

According to passengers, the pilot went to the seat about an hour into the flight and stayed for about 90 minutes. Then, he returned to the cockpit, and another pilot emerged to take a turn napping.

The August 22 flight, United 161, departed from Newark (EWR) at 8:10 p.m., and arrived in Glasgow (GLA) at 7:17 a.m. local time, according to data from flight-tracking website FlightRadar24.

According to United, pilots napping mid-flight is standard practice on a trans-Atlantic route.

Under a set of federal aviation regulations known as FAR 117, pilots are required to rest outside of the cockpit for a certain amount of time during long flights. These flights - which are operated by aircraft with two-pilot flight decks - will have at least three pilots on board who rotate. That way, each of them can get the required rest.

That was the case on this particular flight.

In a statement provided to Business Insider, a United Airlines spokesman said: "The safety of our customers and employees is our top priority. On trans-Atlantic flights such as the flight between GLA and EWR, our pilots are required by the FAA to take a rest break. The aircraft on this route was operated by a cockpit crew of three and this pilot was following the FAA-mandated crew rest requirements."

According to Patrick Smith, a veteran airline pilot who runs the website Ask The Pilot, the key is that there are always two active pilots in the cabin.

"All long-haul flights carry augmented crews that work in shifts," said Smith, who is also author of the book Cockpit Confidential, in an e-mail to Business Insider. "There are always at least two fully qualified pilots in the cockpit at any time."

The rest requirement kicks in on flights that are eight hours or longer, but the EWR-GLA flight is usually shorter than that. However, the United spokesman confirmed that three pilots are scheduled for the flight anyway - allowing each of them to take a turn resting.

As for why the pilot was resting in the passenger cabin - that comes down to the type of aircraft being flown, a Boeing 757.

The 757 is a mid-sized, narrow-body plane, similar to the venerable 737 but with a larger capacity and greater range. It's often used on shorter trans-Atlantic routes, since it's smaller and cheaper to operate than the wide-body jets that operate most long-haul flights.

According to Smith, who flies the 757, small and mid-size aircraft don't have a separate crew rest area.

"We use a designated seat in a first or business class," he said, "usually cordoned off with a curtain."

Larger aircraft, on the other hand, often have a dedicated crew rest compartment for pilots to use.

"There are three different classes of crew rest areas," said Ben Granucci, a senior editor of NYCAviation.com. "Class 1 rest areas are bunks, typically located above the passenger compartment. The pilots are completely separated from the passengers."

The second type, Class 2, is simply a lie-flat first or business class seat in the passenger cabin, sometimes - but not always - separated from the rest of the cabin by a curtain. Class 3 areas are simply recliner-style seats.

Passengers often won't notice the pilots taking their scheduled rest period, but sometimes, a flight crew will take proactive measures to avoid confusion, according to Smith.

"Some pilots will make a public address announcement reminding passengers that they might see a pilot resting in the cabin," he said. "That this is normal and two pilots are always at the controls."