Imagine that there is no atmosphere at all. Just one little oxygen molecule bouncing on Earth’s surface like a bouncy ball. How high does it bounce?
Well, at room temperature it’s moving around 330 m/s, which would let it bounce something like five kilometers up.
This is what the very top of the atmosphere looks like. Radiation from space *does* blast some of it away, but most of it just curves back down.
Earth’s gravity and the magnetic field.
The atmosphere can’t just float away for the same reason we can’t just jump off. Gravity is tying us down.
The sun is constantly spewing out high energy particles, aka solar wind. The earth’s magnetic field protects the atmosphere from mostly getting blown away.
Lighter elements, like helium, can float high enough to be blown away though.
If you do a home-scale experiment, you might get confused. Say that you have a box divided in two halves, and then you suck the air out of the top half to make a vacuum. So, when you pull the divider away, the air in the other half shoots up instantly, but that’s not how our atmosphere works, so what gives?
The answer is that while gravity might be comparatively weak, it has an infinitely long range. In the scope of a box, gravity has no time to really affect how the air moves, but when you’re looking at the planet as a whole, suddenly for an air molecule to “shoot up” into outer space means that it has to travel a hundred kilometers directly up, all the while fighting Earth’s gravity. And that’s only the beginning, because even after all that travel, Earth’s gravity is only about 4% weaker.
For anything to escape Earth’s gravity well permanently, it needs to reach the escape velocity of 11 km/s (at the surface). If you shoot a molecule up any slower than that, it moves so slowly that Earth’s gravity has enough time to slow it down until it stops and starts falling back down. Particles are constantly fighting the gravity and bouncing all over the place, but they all still eventually “fall down” which is why our atmosphere is so densely packed near the surface of the planet.
In comparison, air molecules move at ~500m/s. Which, while fast, is an order of magnitude lower than the required speed. Solar radiation can skim some gases off the top and give individual particles enough of a boost to kick them off permanently, but the amount is insignificant.
If a gas is heavy enough, gravity will keep it within roughly 100 km of the Earth’s surface. This includes oxygen (O2), nitrogen (N2), Carbon Dioxide (CO2), etc. Lighter molecules like hydrogen (H2) or helium (He2) can get enough energy from the sun to reach escape velocity (the speed needed to escape the Earth’s gravitational well) and slowly bleeds off into space. That’s why helium is a limited resource on Earth.
As other people are saying, gravity holds it down. Most air molecules that briefly escape get pulled back down again not long later by gravity. However Earth’s atmosphere actually is thinning rather quickly. During the time of the dinosaurs it may have been as high as 4 or 5 times today’s atmospheric pressure. This might have even allowed some large dinosaurs to fly, even though they might not be able to fly in today’s thinner atmosphere.
[source](https://pubsapp.acs.org/subscribe/archive/ci/30/i12/html/12learn.html?#:~:text=The%20pressure%20could%20have%20been%20~4%E2%80%935%20bar%20from%20Earth’s,bar%20today%20(curve%20C))
Generally speaking, our atmosphere is held onto the planet because of gravity. Gasses, much like all other matter, have mass, and thus gravity affects them as well. Yes they’re not as dense as solid matter and loosely held together but they still have mass.
That being said small amounts of the atmosphere do “fade away into the cosmos”. This happens for a variety of reasons but it’s ultimately a small part of an atmosphere that’s constantly being replenished.
Latest Answers