Rotation of the crankshaft pulls the piston down. At this time, the intake valve is opened, allowing the piston to draw an air/fuel charge into the combustion chamber. As the piston nears the bottom of the stroke, the intake valve closes, sealing the charge in the combustion chamber.
As the crankshaft rotation continues, the piston is pushed up towards the top of the cylinder, compressing the air/fuel mixture. In modern engines the 'compression ratio' is about 8 to 1, meaning the entire contents of the combustion chamber is compressed into an area of about one eighth of its original size. The older stationary engines had compression ratios in the neighborhood of 4 or 5 to 1. Generally, the higher the compression ratio, the more power is obtained from the engine, that is until poor quality and/or low octane values of the fuel begins to have an adverse effect on the combustion. This usually causes the fuel to "diesel" or combust uncontrollably, sometimes called Detonation.
Typically, just before the piston reaches its top most position (Top Dead Center or TDC), the ignition system ignites the now compressed air/fuel charge. Though, in human terms, this burning of the fuel seems more like an instantaneous explosion, it is actually, in a properly running engine, a smooth, rapid flame front that moves from the source of the ignition (spark plug, ignitor, etc.) to all points within the combustion chamber. If the fuel is ignited from several different points due to deposits in the combustion chamber, poor quality fuel or engine problems, several flame fronts can be generated and will collide with each other making what is heard as the common "pinging" sound, sometimes called Preignition. The pressure inside the cylinder increases dramatically because of the combustion taking place and this pressure forces the piston down, which causes the crankshaft to rotate providing usable power output.
By the time the piston is forced most of the way down the cylinder, nearly all of the usable energy created from the burning fuel has been used. At this point, the exhaust valve begins to open and as the crankshaft rotation continues, the rising piston forces the spent gases out of the cylinder and into the exhaust system. Just prior to the piston reaching TDC, the exhaust valve closes and shortly thereafter, the intake valve reopens to start the process over.