Why does the second floor of the Boeing 747 occupy only part of the plane?
The basic design of the Boeing 747 was originally developed to for the US military's CX-HLS program for a large cargo aircraft. One of the main requirements of the program was for cargo to be loaded from the nose, and placing the cockpit above the main cabin made this possible. The Lockheed C-5 Galaxy was selected, but Boeing carried the same features over to the 747.

In the 1960s when the 747 was being developed, some believed that supersonic aircraft would be taking over the long-haul travel market. The relatively short "hump" was retained not for extra passenger capacity, but so that if the passenger market dried up, they could keep producing the aircraft for the cargo market.

Boeing did extend the "hump" further back to add capacity on passenger versions, first on the 747-300 (and later retrofitted to a few -100 and -200 planes), and again on the 747-8I. Extending the second deck all the way back would create too many major changes to the structure and aerodynamics of the airplane, essentially making it a completely new model. Boeing did study a full double-deck model to compete with the A380, but opted to focus on a smaller, more fuel-efficient market with the 787 instead.