The simple answer is yes, pilots do, and are allowed to sleep during flight but there are strict rules controlling this practice. Pilots would only normally sleep on long haul flights, although sleep on short haul flights is permitted to avoid the effects of fatigue.
For long flights over twelve hours, there are one or two relief pilots onboard so that the two pilots who performed the takeoff can take a break and get some sleep or relax. There are just two pilots on short long-haul flights of eight or nine hours.
Aviation regulators set the total hours pilots fly and how much sleep they must get between flights. During ultra-long-haul flights, pilots sleep in special cabins, which passengers can't access.
Pilots have resting cabins where they can sleep on long-haul flights. The cabins are usually located behind the cockpit and above first class.
One important issue was how to ensure that the co-pilot didn't also accidentally fall asleep. This has been a real concern for many years in aviation, with some studies reporting that as much as 50% of pilots accidentally fall asleep during flights.
I've known pilots who are scared of flying. In the industry, they are known as seagulls because you have to throw rocks at them to get them to fly and, even then, they squawk the entire time. One mate of mine who wasn't keen on flying said he coped by always taking a taxi to the airport.
They're not glamorous, but they're very comfortable, with padded bunks and sometimes even in-flight entertainment! With 14- to 18-hour flights no longer unusual, pilots and cabin crew have legally mandated rest times —and airlines also realise that a rested, refreshed crew member is a happy crew member.
While there are many pilot and flight attendant couples, and many flight attendants married or committed to other flight attendants, and many pilots with the same connections with other pilots, several factors have made those connections less likely.
More than two pilots
Generally, if the flight is longer than eight hours, a third pilot (second officer) is required onboard. That requirement may vary slightly between operators.
Easier Navigation
Navigating at night can actually be much easier than during the day. Large conurbations and their associated street lights can be seen from miles away. Making it easy to pinpoint them and fly towards them. Roads are also much easier to pick out against the surrounding terrain.
Managing fatigue is a challenge, particularly when flying overnight (red-eye) flights. Some countries allow pilots to take controlled naps to improve alertness during the landing. So far, the U.S. has not allowed this fatigue mitigation. Pilots keep flight deck lights up, and engage in conversation to help keep alert.
Night flying brings its own set of challenges. Fatigue becomes a potential issue for pilots even when they are relatively used to flying at night. Poor lighting in the aircraft can cause issues for navigation during night flights as well. The night sky makes it hard to read instruments and discern surface features.
Per diem is generally paid continuously for every hour you are away from base, even while you are sleeping! It generally starts around $1.70/hour and goes up based on company and domestic/international rates.
The pilots can eat in the cockpit, but they tend to not eat at the same time, so that one is always at the controls.
Fatigue is particularly prevalent among pilots because of "unpredictable work hours, long duty periods, circadian disruption, and insufficient sleep". These factors can occur together to produce a combination of sleep deprivation, circadian rhythm effects, and 'time-on task' fatigue.
The Bureau of Labor Statistics reported the median U.S. pilot salary at $211,790 in 2022. This means 50% of pilots earn more than this, and 50% earn less. However, there are pilots working for major airlines making more than $700,000 per year.
Though rest is the priority, I try to do more than just rest in the hotel for longer overnights. On the welcomed but rare long overnight, I've made my way through historic sites, a presidential library, local independent bookstores, and unique landmarks and restaurants.
Flight times within the duty periods are restricted to a maximum of 8 hours for flight crews consisting of one pilot and 10 hours for flight crews consisting of two pilots. The 8-hour and 10-hour flight time limitations include any additional commercial flying performed by the flight crew during the period.
The majority of the time, though, many flight attendants aren't going to wake you up if you're napping during the flight. In that case, you can ask to be woken up for the meal.
The chances of a pilot marrying a flight attendant from their own airline are 1 in 7, according to research published in Air Line Pilot Magazine. This statistic is a telling indication of the unique bond that pilots and flight attendants share.
Flight Attendants and Pilots Do Share the Same Hotel, But Do Not Share a Room. The cabin crew team and pilots normally take a company-hired bus to reach their hotel and the team check-in separately. They sleep together in the same hotel, but they have their own separate rooms, and they usually don't share.
 Take Advantage of Naps
A 20-30-minute map is all you need to help fight pilot fatigue. A short burst of rest will help to improve alertness in your day. However, you want to be sure your nap isn't too long.
In a given month, flight crew might spend half of their nights in hotels, if not more. Hotels are booked and paid for by the airline if the pilot is actively on a duty assignment mid-trip. However, the crew member must find and pay for hotels needed on the front or back end of a trip.
How Much Do Pilots Make an Hour? » According to The May 2021 Occupational Outlook Handbook, the Bureau of Labor Statistics, the salary for commercial pilots is $99,640 per year. The median annual wage for airline pilots, copilots and flight engineers is $202,180.