The engine casing is formed from two main parts, the block and the head. The head of the engine contains the valves, fuel injection and camshaft; the block contains the pistons and crankshaft, and it is this part that connects to the flywheel and transmits power to the rest of the car. They are both made of cast metal, and need to be able to separate, in order to fix any damage to the valves and the pistons.
However, oil and water also need to flow between the block and head; oil as a lubricant, water as a coolant. These flows must not mix or leak, so the head gasket is inserted between the two, in order to seal the system.
Problems occur if the head gasket becomes distorted or split, causing the coolant and lubrication systems to fail. Signs that this has happened can include engine failure, and blue or white exhaust smoke (blue indicates a leak of lubricant; white a leak of coolant).
When your car comes in for a checkup, the state of the head gasket is carefully checked by measuring the pressure of the oil and coolant, which will detect any leaks.