The escape velocity of earth is, $v_e=\sqrt{2gR}$. Since acceleration due to gravity and radius of earth is large, escape velocity is also large.
The root mean square velocity of gas molecules is, \[c_{\text{rms}}=\sqrt{\frac{RT}{M_m}}\]
The temperature of earth is not so high. So, the rms velocity of gas is very less compared to the escape velocity. Thus, air cannot escape from the earth. So, earth can hold a generous portion of the atmosphere. An exception is hydrogen. Hydrogen has high rms velocity because it has least molecular mass; so it escapes as soon as it is formed.