Just like any other gas or mixture of gases, the gas molecules are zipping around in all different directions and with a whole range of different speeds.
Those that happen to be moving at a speed greater than the Earth's "escape velocity", AND are pointed away from Earth, AND don't hit any other molecules before they escape, are lost.
With the combination of Earth's escape velocity, and the temperatures, thickness, and density of the atmosphere, that process happens slowly enough to have maintained an atmosphere around this planet until now.
Personally, I hope it hangs around for a while longer. But with the constant increase in temperature that's been going on, you never know . . .