The earth is able to retain its atmosphere because of
The escape velocity of earth is approximately 11.2km/s. This is greater than the root-mean-square velocities of the atmospheric gases. Hence, the gases are unable to escape into the vacuum of space.