Today, internal combustion engines in cars, trucks, motorcycles, aircraft, construction machinery and many others, most commonly use a four-stroke cycle. The four strokes refer to intake, compression, combustion (power), and exhaust strokes that occur during two crankshaft rotations per working cycle of the gasoline engine and diesel engine. A less technical description of the four-stroke cycle is, "Suck, Squeeze, Bang, Blow"
The cycle begins at top dead center (TDC), when the piston is farthest away from the axis of the crankshaft. A stroke refers to the full travel of the piston from Top Dead Center (TDC) to Bottom Dead Center (BDC). (See Dead centre.)
Stroke 1 of 4 "Suck": On the intake or induction stroke of the piston , the piston descends from the top of the cylinder to the bottom of the cylinder, reducing the pressure inside the cylinder. A mixture of fuel and air is forced by atmospheric (or greater) pressure into the cylinder through the intake port. The intake valve(s) then close.
Stroke 2 of 4 "Squeeze": With both intake and exhaust valves closed, the piston returns to the top of the cylinder compressing the fuel-air mixture. This is known as the compression stroke.
Stroke 3 of 4 "Bang": While the piston is at or close to Top Dead Center, the compressed air–fuel mixture is ignited, usually by a spark plug (for a gasoline or Otto cycle engine) or by the heat and pressure of compression (for a diesel cycle or compression ignition engine). The resulting massive pressure from the combustion of the compressed fuel-air mixture drives the piston back down toward bottom dead center with tremendous force. This is known as the power stroke, which is the main source of the engine's torque and power.
Stroke 4 of 4 "Blow": During the exhaust stroke, the piston once again returns to top dead center while the exhaust valve is open. This action evacuates the products of combustion from the cylinder by pushing the spent fuel-air mixture through the exhaust valve(s).
The four-stroke engine was first patented by Alphonse Beau de Rochas in 1861. Before, in about 1854–57, two Italians (Eugenio Barsanti and Felice Matteucci) invented an engine that was rumored to be very similar, but the patent was lost.
The first person to actually build a car with this engine was German engineer Nicolaus Otto. That is why the four-stroke principle today is commonly known as the Otto cycle and four-stroke engines using spark plugs often are called Otto engines. The Otto cycle consists of adiabatic compression, heat addition at constant volume, adiabatic expansion and rejection of heat at constant volume.
Internal combustion engine power primarily originates from the expansion of gases in the power stroke. Compressing the fuel and air into a very small space increases the efficiency of the power stroke, but increasing the cylinder compression ratio also increases the heating of the fuel as the mixture is compressed (following Charles's law).
A highly flammable fuel with a low self-ignition temperature can combust before the cylinder reaches top-dead-center (TDC), potentially forcing the piston backwards against rotation. Alternately, a fuel which self-ignites at TDC but before the cylinder has started downwards can damage the piston and cylinder due to the extreme thermal energy concentrated into a very small space with no relief. This damage is often referred to as engine knocking and can lead to permanent engine damage if it occurs frequently.
The octane rating is a measure of the fuel's resistance to self-ignition, by increasing the temperature at which it will self-ignite. A fuel with a greater octane rating allows for a much higher compression ratio without the risk of damage due to self-ignition.
Diesel engines rely on self-ignition for the engine to function. They solve the engine damage problem by separately injecting high-pressure fuel into the cylinder shortly before the piston has reached TDC. Air without fuel can be compressed to a very high degree without concern for self-ignition, and the highly pressurized fuel in the fuel injection system cannot ignite without the presence of air.
The maximum amount of power generated by an engine is determined by the maximum amount of air ingested. The amount of power generated by a piston engine is related to its size (cylinder volume), whether it is a two-stroke or four-stroke design, volumetric efficiency, losses, air-to-fuel ratio, the calorific value of the fuel, oxygen content of the air and speed (RPM). The speed is ultimately limited by material strength and lubrication. Valves, pistons and connecting rods suffer severe acceleration forces. At high engine speed, physical breakage and piston ring flutter can occur, resulting in power loss or even engine destruction. Piston ring flutter occurs when the rings oscillate vertically within the piston grooves they reside in. Ring flutter compromises the seal between the ring and the cylinder wall which results in a loss of cylinder pressure and power. If an engine spins too quickly, valve springs cannot act quickly enough to close the valves. This is commonly referred to as 'valve float', and it can result in piston to valve contact, severely damaging the engine. At high speeds the lubrication of piston cylinder wall interface tends to break down. This limits the piston speed for industrial engines to about 10 m/sec.
The output power of an engine is dependent on the ability of intake (air–fuel mixture) and exhaust matter to move quickly through valve ports, typically located in the cylinder head. To increase an engine's output power, irregularities in the intake and exhaust paths, such as casting flaws, can be removed, and, with the aid of an air flow bench, the radii of valve port turns and valve seat configuration can be modified to reduce resistance. This process is called porting, and it can be done by hand or with a CNC machine.
One way to increase engine power is to force more air into the cylinder so that more power can be produced from each power stroke. This was originally done using a type of air compression device known as a supercharger, which is powered by the engine crankshaft.
Supercharging increases the power output limits of four-stroke engine, but the supercharger is always running. Continuous compression of the intake air requires some mechanical energy to accomplish, so the supercharger has a cost of reduced fuel efficiency when the engine is operating at low power levels or when the engine is simply unloaded and idling.
The turbocharger was designed as a part-time method of compressing more air into the cylinder head. It consists of a two piece, high-speed turbine assembly with one side that compresses the intake air, and the other side that is powered by the exhaust gas outflow.
When idling, and at low-to-moderate speeds, the turbocharger is not engaged and the engine operates in a naturally-aspirated manner. When much more power output is required, the engine speed is increased until the exhaust gases are sufficient to 'spin up' the turbocharger's turbine to start compressing much more air than normal into the intake manifold.
Turbocharging allows for more efficient engine operation at low-to-moderate speeds, but there is a design limitation known as turbo lag. The increased engine power is not immediately available, due to the need to sharply increase engine RPM to spin up the turbo, before the turbo starts to do any useful air compression.
The rod-to-stroke ratio is the ratio of the length of the connecting rod to the length of the piston stroke. A longer rod will reduce the sidewise pressure of the piston on the cylinder wall and the stress forces, hence increasing engine life. It also increases cost and engine height and weight.
A "square engine" is an engine with a bore diameter equal to its stroke length. An engine where the bore diameter is larger than its stroke length is an oversquare engine, conversely, an engine with a bore diameter that is smaller than its stroke length is an undersquare engine.
The valves are typically operated by a camshaft rotating at half the speed of the crankshaft. It has a series of cams along its length, each designed to open a valve during the appropriate part of an intake or exhaust stroke. A tappet between valve and cam is a contact surface on which the cam slides to open the valve. Many engines use one or more camshafts “above” a row (or each row) of cylinders, as in the illustration, in which each cam directly actuates a valve through a flat tappet. In other engine designs the camshaft is in the crankcase, in which case each cam contacts a push rod, which contacts a rocker arm which opens a valve. The overhead cam design typically allows higher engine speeds because it provides the most direct path between cam and valve.
Valve clearance refers to the small gap between a valve lifter and a valve stem that ensures that the valve completely closes. On engines with mechanical valve adjustment excessive clearance will cause noise from the valve train. Typically the clearance has to be readjusted each 20,000 miles with a feeler gauge.
Most modern production engines use hydraulic lifters to automatically compensate for valve train component wear. Dirty engine oil may cause lifter failure.
Otto engines are about 35% efficient – in other words, 35% of the energy generated by combustion is converted into useful rotational energy at the output shaft of the engine, while the remainder appears as waste heat.By contrast, a six-stroke engine may convert more than 50% of the energy of combustion into useful rotational energy.
Modern engines are often intentionally built to be slightly less efficient than they could otherwise be. This is necessary for emission controls such as exhaust gas recirculation and catalytic converters that reduce smog and other atmospheric pollutants. Reductions in efficiency may be counteracted with an engine control unit using lean burn techniques. 
Starting position, intake stroke, and compression stroke.
Ignition of fuel, power stroke, and exhaust stroke.
From Nikolaus Otto German engineer