The MP38 submachine gun was a pretty successful design and performed the tasks that it was designed for well. However, it could not be manufactured quickly because of the way that some of the parts were made (many parts were machined). The original manufacturer of the MP38, Erma, gave the design to C.P. Haenel to help with production, but even these two companies together could not meet the demand for these weapons from the German Army. As a matter of fact, they could not even meet their own production targets that they had set themselves! By 1939, the German War Office asked for changes in the production methods to speed up manufacturing.
Both Erma and Haenel were relatively smaller arms manufacturing companies, so larger companies, such as Krupp, Steyr and Merz Werke, were recruited to help. The engineers from these larger companies were experienced in modern mass production technologies and they made changes to the MP38 model to speed up its production rate. The new model was introduced in 1940 and was called the MP40.
A MP40 with the stock folded. Click on the image to enlarge.
Image licensed under the Creative Commons Attribution-Share Alike 3.0 Unported license
A MP40 with the stock extended. Click on the image to enlarge
Image licensed under the Creative Commons Attribution-Share Alike 3.0 Unported license
In the MP38, many parts were machined, which made the process of manufacturing expensive and slow. In particular, the receiver took multiple machining operations on a block of steel, to make the final product. Many of the parts of the MP40, on the other hand, was made by stamping out steel parts using dies and high speed presses and then joining the parts together by using brazing and spot-welding techniques. Only the barrel and the bolt were machined in the MP40. This made the production rate much faster. Over 1.1 million MP40 submachine guns were produced between 1940 and 1945.
Therefore, the MP38 was one of the last submachine guns to be largely manufactured with machining technologies and the MP40 was one of the first submachine guns designed specifically to be manufactured quickly and cheaply. This is why the quality and finish of the MP38 is usually superior to the MP40, but the MP40 is just as effective as the MP38.
One weakness of the MP40 is that it uses the same double-column single-feed magazines as the MP38 and therefore, it has the same issues with dirt and jamming.
The MP40 comes in multiple variants as the Germans continued to improve the design to reduce the manufacturing time. Erma, Haenel and Steyr were the main manufacturers and a number of the parts were made by other subcontractors. For instance, one of the manufacturers of the plastic grips was the German electrical giant AEG (these days, they are known as AEG/Electrolux). Krupp and Merz Werke produced a lot of the stamped parts (tubes, frames etc.) for both Erma and Haenel (Steyr produced their own stampings), Mauser Werke supplied barrels and so on.
The MP40 is really the prototype for a number of other submachine guns that have been made since. It influenced the development of the US M3 Grease gun and the British Sten gun, as both the US and the UK saw the need for a rapid-firing weapon that could be produced quickly and cheaply. It is one of the first weapons to use plastics instead of wood. The forward folding stock design was first designed for the MP 40 and later copied by other people, notably the AK family.
Interestingly, the MP40 was often referred to by Allied troops as the "schmeisser", named after the famed German designer, Hugo Schmeisser. In reality though, he had very little to do with this design, as most of it was done by Berthold Geipel and Heinrich Vollmer and later improved by mass-production specialist engineers at other companies. About the only contribution of Hugo Schmeisser to the design was the magazine, which Hugo Schmeisser had designed and patented for another weapon, but the German War Office insisted on using Schmeisser's magazine design for the MP38 and MP40. Interestingly, Hugo Schmeisser did design the MP41, which is largely a MP40, but using a wooden stock and a selector lever from the MP-28, which Schmeisser had worked on earlier.
Even though the German factories stopped producing the MP40 after World War II, they remained in service with other countries for several years since. For instance, France used the MP40 during the 1950s and 1960s and Norway still used them until about 1990 or so.