okay so basically gases are made up of a bunch of tiny particles called molecules
these molecules are not just sitting around not moving, they are indeed moving around quite a bit
the speed at which they are moving around is directly related to the *temperature* of the gas
if the gas is higher, then there is more energy in the gas, and so the particles are going to moving around faster
however, all of the particles are not moving around at the same speed. Some are moving faster than others, some slower, and there is an average speed. It looks like a Bell Curve *sort of*.
So basically, there is some small fraction of the molecules that is moving *way faster* than the rest of the molecules. Since the velocity of the molecule is influenced by mass, this means the lightest molecules will have a better chance of getting *really really* fast.
And so, there are some molecules way up at the top of the atmosphere that are going fast enough to escape the Earth's gravitational pull. These molecules would be Hydrogen and Helium most likely because they weigh the least.
And so yeah, the gas in the atmosphere acts very much like the water in the ocean. Except there's no "surface" to the atmosphere because gas molecules are not attracted to one another as much as liquid molecules are.
In fact, I'm pretty sure that the molecules in a gas are not connected whatsoever. While the molecules in a liquid have a little bit of a bond. I don't know very much about the specifics of that, though.
Gas molecules zip around totally free and collide with one another. The energy giving the molecules their motion is related to the temperature of the gas.
hopefully some of that helps