How do gaskets work?
The compression and subsequent displacement of the material when gasket material is compressed between two surfaces causes a seal to be formed that is maintained with movement, vibration, temperature fluctuations and the presence of chemicals, fluids, oils and steam. Different gasket materials are used for different applications. The materials are chosen based on their ability to resist the required operating environment.
For a more in-depth discussion about how gaskets are used within tolerance we have an article Seeking Precision With Rubber Parts.