Submarine
Among the pioneers of this alternative solution was the very first submarine of the Swedish Navy, HSwMS Hajen (later renamed Ub no 1), launched in 1904. While its design was generally inspired by the first submarine commissioned by the US Navy, USS Holland, it deviated from the latter in at least three significant ways: by adding a periscope, by replacing the gasoline engine by a semidiesel engine (a hot-bulb engine primarily meant to be fueled by kerosene, later replaced by a true diesel engine) and by severing the mechanical link between the combustion engine and the propeller by instead letting the former drive a dedicated generator. By so doing, it took three significant steps toward what was eventually to become the dominant technology for conventional (i.e., non-nuclear) submarines.

In the following years, the Swedish Navy added another seven submarines in three different classes (2nd class, Laxen class, and Braxen class) using the same propulsion technology but fitted with true diesel engines rather than semidiesels from the outset. Since by that time, the technology was usually based on the diesel engine rather than some other type of combustion engine, it eventually came to be known as diesel–electric transmission.
Like many other early submarines, those initially designed in Sweden were quite small (less than 200 tonnes) and thus confined to littoral operation. When the Swedish Navy wanted to add larger vessels, capable of operating further from the shore, their designs were purchased from companies abroad that already had the required experience: first Italian (Fiat-Laurenti) and later German (A.G. Weser and IvS). As a side-effect, the diesel–electric transmission was temporarily abandoned.
However, diesel–electric transmission was immediately reintroduced when Sweden began designing its own submarines again in the mid-1930s. From that point onwards, it has been consistently used for all new classes of Swedish submarines, albeit supplemented by air-independent propulsion (AIP) as provided by Stirling engines beginning with HMS Näcken in 1988.

Another early adopter of diesel–electric transmission was the US Navy, whose Bureau of Engineering proposed its use in 1928. It was subsequently tried in the S-class submarines S-3, S-6, and S-7 before being put into production with the Porpoise class of the 1930s. From that point onwards, it continued to be used on most US conventional submarines.
Apart from the British U-class and some submarines of the Imperial Japanese Navy that used separate diesel generators for low speed running, few navies other than those of Sweden and the US made much use of diesel–electric transmission before 1945. After World War II, by contrast, it gradually became the dominant mode of propulsion for conventional submarines. However, its adoption was not always swift. Notably, the Soviet Navy did not introduce diesel–electric transmission on its conventional submarines until 1980 with its Paltus class.
If diesel–electric transmission had only brought advantages and no disadvantages in comparison with a system that mechanically connects the diesel engine to the propeller, it would undoubtedly have become dominant much earlier. The disadvantages include the following:

It entails a loss of fuel-efficiency as well as power by converting the output of the diesel engine into electricity. While both generators and electric motors are known to be very efficient, their efficiency nevertheless falls short of 100 percent.
It requires an additional component in the form of a dedicated generator. Since the electric motor is always used to drive the propeller it can no longer step in to take on generator service as well.
It does not allow the diesel engine and the electrical motor to join forces by simultaneously driving the propeller mechanically for maximum speed when the submarine is surfaced or snorkeling. This may, however, be of little practical importance inasmuch as the option it prevents is one that would leave the submarine at a risk of having to dive with its batteries at least partly depleted.
The reason why diesel–electric transmission has become the dominant alternative in spite of these disadvantages is of course that it also comes with many advantages and that, on balance, these have eventually been found to be more important. The advantages include the following:

It reduces external noise by severing the direct and rigid mechanical link between the relatively noisy diesel engine(s) on the one hand and the propeller shaft(s) and hull on the other. With stealth being of paramount importance to submarines, this is a very significant advantage.
It increases the readiness to dive, which is of course of vital importance for a submarine. The only thing required from a propulsion point of view is to shut down the diesel(s).
It makes the speed of the diesel engine(s) temporarily independent of the speed of the submarine. This in turn often makes it possible to run the diesel(s) at close to optimal speed from a fuel-efficiency as well as durability point of view. It also makes it possible to reduce the time spent surfaced or snorkeling by running the diesel(s) at maximum speed without affecting the speed of the submarine itself.
It eliminates the clutches otherwise required to connect the diesel engine, the electric motor, and the propeller shaft. This in turn saves space, increases reliability and reduces maintenance costs.
It increases flexibility with regard to how the driveline components are configured, positioned, and maintained. For example, the diesel no longer has to be aligned with the electric motor and propeller shaft, two diesels can be used to power a single propeller (or vice versa), and one diesel can be turned off for maintenance as long as a second is available to provide the required amount of electricity.
It facilitates the integration of additional primary sources of energy, beside the diesel engine(s), such as various kinds of air-independent power (AIP) systems. With one or more electric motors always driving the propeller(s), such systems can easily be introduced as yet another source of electric energy in addition to the diesel engine(s) and the batteries.

Snorkel: During World War II the Germans experimented with the idea of the schnorchel (snorkel) from captured Dutch submarines but did not see the need for them until rather late in the war. The schnorchel is a retractable pipe that supplies air to the diesel engines while submerged at periscope depth, allowing the boat to cruise and recharge its batteries while maintaining a degree of stealth.
Especially as first implemented however, it turned out to be far from a perfect solution. There were problems with the device's valve sticking shut or closing as it dunked in rough weather. Since the system used the entire pressure hull as a buffer, the diesels would instantaneously suck huge volumes of air from the boat's compartments, and the crew often suffered painful ear injuries. Speed was limited to 8 knots (15 km/h), lest the device snap from stress. The schnorchel also created noise that made the boat easier to detect with sonar, yet more difficult for the on-board sonar to detect signals from other vessels. Finally, allied radar eventually became sufficiently advanced that the schnorchel mast could be detected beyond visual range.
While the snorkel renders a submarine far less detectable, it is thus not perfect. In clear weather, diesel exhausts can be seen on the surface to a distance of about three miles, while "periscope feather" (the wave created by the snorkel or periscope moving through the water) is visible from far off in calm sea conditions. Modern radar is also capable of detecting a snorkel in calm sea conditions.

The problem of the diesels causing a vacuum in the submarine when the head valve is submerged still exists in later model diesel submarines but is mitigated by high-vacuum cut-off sensors that shut down the engines when the vacuum in the ship reaches a pre-set point. Modern snorkel induction masts have a fail-safe design using compressed air, controlled by a simple electrical circuit, to hold the "head valve" open against the pull of a powerful spring. Seawater washing over the mast shorts out exposed electrodes on top, breaking the control, and shutting the "head valve" while it is submerged. US submarines did not adopt the use of snorkels until after WWII.

Air-independent propulsion: During World War II, German Type XXI submarines (also known as "Elektroboote") were the first submarines designed to operate submerged for extended periods. Initially they were to carry hydrogen peroxide for long-term, fast air-independent propulsion, but were ultimately built with very large batteries instead. At the end of the War, the British and Soviets experimented with hydrogen peroxide/kerosene (paraffin) engines that could run surfaced and submerged. The results were not encouraging. Though the Soviet Union deployed a class of submarines with this engine type (codenamed Quebec by NATO), they were considered unsuccessful.
The United States also used hydrogen peroxide in an experimental midget submarine, X-1. It was originally powered by a hydrogen peroxide/diesel engine and battery system until an explosion of her hydrogen peroxide supply on 20 May 1957. X-1 was later converted to use diesel–electric drive.
Today several navies use air-independent propulsion. Notably Sweden uses Stirling technology on the Gotland-class and Södermanland-class submarines. The Stirling engine is heated by burning diesel fuel with liquid oxygen from cryogenic tanks. A newer development in air-independent propulsion is hydrogen fuel cells, first used on the German Type 212 submarine, with nine 34 kW or two 120 kW cells. Fuel cells are also used in the new Spanish S-80-class submarines although with the fuel stored as ethanol and then converted into hydrogen before use.