When a three-phase contact line moves along a solid surface, the contact angle no longer corresponds to the static equilibrium angle but is larger when the liquid is advancing and smaller when the liquid is receding. The difference between the advancing and receding contact angles, i.e., the contact angle hysteresis, is of paramount importance in wetting and capillarity. For example, it determines the magnitude of the external force that is required to make a drop slide on a solid surface. Until now, fundamental origin of the contact angle hysteresis has been controversial. Here, this origin is revealed and a quantitative theory is derived. The theory is corroborated by the available experimental data for a large number of solid-liquid combinations. The theory is applied in modelling the contact angle hysteresis on a textured surface, and these results are also in quantitative agreement with the experimental data.