Steam engines are, superficially, simple. The chemical energy of a fuel is transformed into mechanical energy by boiling water and using the energy in the steam to create movement. Energy is absorbed when liquid water is transformed into gaseous steam. This energy is known as the "Latent Heat of Evaporation". This latent heat is energy needed to break the forces which bind the molecules of the water together in liquid form; these are particularly strong in the case of water due to what are known as hydrogen bonds, which cause an electrostatic attraction between the water molecules.
The earliest steam engines used only this latent heat. This was the principle behind Savery's engine of 1698. The steam made from boiling water was admitted to a large chamber and the steam condensed by cooling it. This created a vacuum and water was drawn into the chamber. It was not particularly effective, but the idea was developed by Newcomen, who replaced the chamber with a piston and cylinder, and used a spray of water to condense the steam. This was the driving force behind the atmospheric beam engines which began to come into use around 1712 for pumping water out of mines. They did not make efficient use of the energy but in coal mines, where they were mostly used, there was a plentiful supply of fuel that was not of good enough quality to be sold.
About fifty years later, working at the University of Glasgow, James Watt improved the engines by introducing a separate condenser. This meant that the cylinder was not cooled down after every stroke, thereby reducing the waste of energy. Although the early Watt engines still used steam at atmospheric pressure, there was an increase in efficiency as the steam was able to expand in a cylinder against a vacuum on the other side of the piston.
In 1776, Watt went into partnership with Matthew Boulton and they set up a manufactory in Birmingham. By this time, improvements in engineering techniques had made it possible to produce accurate components, especially the pistons and cylinders which were critical if the machines were to perform efficiently. In the final years of the eighteenth century, Watt and others made other important improvements, including "double-acting" cylinders which used steam on both the "up" and "down" strokes, devices for admitting the steam to the cylinders automatically (valve gear), and the application of connecting rods and cranks to convert reciprocal motion to rotary motion, in the first place to drive flywheels.
There is a curiosity here. Because the connecting rod and crank were the subject of patents, Boulton and Watt developed a "sun-and-planets" arrangement to transform reciprocating motion to rotary motion. However, Joseph Needham, an expert on Chinese technology, writing in the 1950s, discovered that connecting rod/crank arrangements used for corn grinding were well-known in China by the end of the first millennium, and in Europe by the middle ages. Foot-operated potters' wheels are also ancient, which makes one wonder about the patent.
The next major improvement was the use of pressurised steam. The advantage is that water under pressure boils at a higher temperature, which means that the hotter steam, which contains more energy, can undergo more expansion before it is cool enough to condense.
Although "strong steam" had been advocated for several decades before it was adopted, Watt was opposed, partly for safety reasons, as the materials available at the time were not reliable. High pressure boilers were liable to explode. This held back development, but by the beginning of the nineteenth century, high pressure engines - using steam at three or four times atmospheric pressure - were practicable. Being more compact, they could be used as a replacement for horses to drive vehicles on the improved roads of the time, as well as on the network of tracked waggonways which were developing around coal and tin mines.