The first commercial piston-type steam engine was produced in 1698. It was a primitive device that was used to remove water from underground mines.
In 1712 a successful steam engine (again using up-down motion to pump water from mines) was invented by Thomas Newcomen, called the "atmospheric engine". Below is a diagram showing operation of this engine. The boiler is to the bottom right. Water is blue, and steam is pink in this animation.
What is not obvious to modern eyes is that the power stroke on these early engines was not due to steam pressure from the steam entering the cylinder. The boilers of the day were not able to contain enough steam pressure to push anything. The steam used in these engines was at atmospheric pressure, same as your tea kettle. The power stroke on this engine occurs when the steam condenses and creates a vacuum underneath the piston.
Here is how it operates: A valve at the top of the boiler opens, and the cylinder fills with steam at atmospheric pressure. The reason the piston moves up is due to the weight of the pump assembly (not shown) pulling down the rod on the left.
The steam valve closes and a second water valve opens. This valve sprays gravity-fed water into the cylinder, condensing the steam. As the steam suddenly condenses, it creates a vacuum. This vacuum pulls the piston back to the bottom of the cylinder, and the process repeats. The steam and water valves would be operated by linkages connected to the piston, so that they would open and close at the correct point in the cycle. Very clever!
There was also a third valve to drain water from the bottom of the cylinder that is not shown in this animation.
But while this engine worked well enough, there was a great deal of room for improvement.
The biggest problem with this design is that the cylinder and piston are cooled down a great deal by the spray of water on the down-stroke. Thus when steam is admitted for the next cycle, a lot of the steam condenses on the cold metal parts. This design, while very creative, wasted a great deal of steam re-heating the cylinder/piston assembly each stroke, and was therefore very inefficient.
Meet James Watt.
His brilliant contribution to steam power was to condense the steam in a different vessel. He did this by connecting the bottom of the cylinder to a separate vessel called a condenser. His condenser was a large pipe submerged in water
Another huge improvement he made was to keep the cylinder at the same temperature as the incoming steam by surrounding it with a "steam jacket" - passages in the cylinder wall that steam continously flowed through and heated.
The animation below shows the improvements. Steam from the boiler enters the "steam jacket", a space between and inner and outer cylinder. It enters the bottom of the cylinder when the upper valve is open and the lower valve is shut. The piston moves up (again due to the weight of the equipment on the left side of the rocker arm, not steam pressure). When the piston reaches top of travel, the steam valve shuts and the valve to the condenser opens. As the steam condenses in the condenser, it places the bottom of the cylinder under vacuum and pulls the piston down - the power stroke. The process then repeats.
Lastly, to have practical, useful power, we need to have rotary motion. If we attach a large wheel with lots of mass to keep it in motion between pulses, we have the basic technology for the industrial revolution!