How come gas molecules don't settle down? If the earth's gravity exerts a net downward gravitational force on all air molecules, how come the molecules don't eventually lose their momentum and all settle down? How is the atmosphere is still miles thick after billions of years?
 A: The other answers are correct but to understand them you have to get an idea of how much thermal energy does an average molecule have.
According to Maxwell-Boltzmann distribution, the most probable speed of an air (say, nitrogen) molecule at room temperature is $v_p = \sqrt { \frac{2kT}{m} } = 422 m/s$. Without collisions with other molecules it can travel upwards $h=\frac{v_{0}^{2}}{2g}$ = 9 kilometers before the gravity stops it and pulls back to Earth.
Basically, potential energy of molecules in gravitational field is too small compared to their kinetic energy to keep them low.
Update: Still, gravity is the reason why we have atmosphere after billions of years.
A: The current answers all dive into the nitty-gritty, so I thought I'd provide a more conceptual answer.  First of all, if you ignore all interaction, radiative, etc. effects and just consider air to be an ideal gas under the influence of gravity, then it wouldn't settle down because of conservation of energy - there's nowhere for the air molecules' initial kinetic energy to go.
But in practice, air does have a small but nonzero viscosity, so over the course of billions of years, at zero temperature internal friction would slow down the air molecules (radiating the lost kinetic energy away as heat) and they would indeed settle down to the ground.
But the constant influx of energy from the Sun keeps the atmosphere at high temperature.  The key insight is that the state with all the air stationary down at the ground has extremely low entropy - much less than the state where the molecules are whizzing around all over the place.  Since high temperature favors states with high entropy, the atmospheric temperature keeps the air molecules up in the air because that state has such high entropy.
If the Sun were to suddenly go dark, then the Earth's atmosphere would eventually cool down to the point where it would indeed settle down to the ground (at least until it reaches a density high enough that interactions between the molecules becomes important).  In practice, this won't happen, because when the Sun dies, it will become a red giant that engulfs the Earth completely.
A: The key ingredient is temperature.
If it were zero then all the air would indeed just fall down to the ground (actually, this is a simplification I'll address later). As you increase the temperature the atoms of the ground will start to wiggle more and they'll start to kick the air molecules giving them non-zero average height. So the atmosphere would move a little off the ground. The bigger the temperature is the higher the atmosphere will reach.
Note: there are number of assumptions above that simplify the picture. They are not that important but I want to provide a complete picture:


*

*Even at the zero temperature the molecules would wiggle a little because of quantum mechanics

*the atmosphere would freeze at some point (like 50K) so under that temperature it would just lie on the ground

*I assumed that the ground and the atmosphere have the same temperature because they are in the thermal equilibrium; in reality their temperatures can differ a little because of additional slow heat-transfer processes


To leave you with something a little bit more concrete (although quite simplified), statistical mechanics tells us that probability $p$ that some portion of the system will occupy a given energy $E$ level is $p \propto \exp({-E \over kT})$ where $k$ is a Boltzmann constant (note that you have to normalize this probability to 1 by summing over all energy levels; that's why it's only proportional, $\propto$).
For the atmosphere of ideal gas where molecules have only potential energy (kinetic energy is not important here because the molecules don't interact with each other in the ideal gas) we have $E = mgh$. This gives us $p \propto \exp({-mgh \over kT})$. You can see that atmosphere "wants" to get lower ($p$ is bigger for $h$ lower) but the temperature "forces" it to go up. Play with the equation for different values of $T$ and $g$ (gravity strength) to see what happens.
A: This is because the sun is supplying them with kinetic energy all the time, which you know is temperature. Then the ideal gas law states p*V=nRT, so the volume keeps pretty much constant.
The pressure is causes by the electrostatic repulsion between the molecules pushing them apart, and the gravity pulling them towarsd earth.
Another important reason they dont 'settle down' is that temperature is the lowest form of energy, this means that what you actually ask for cannot happen in any closed system, the temperature energy can only go towards heating something else, the core of the atmosphere is in this sense not a perfect analogy, because some of its energy will be "lost" to heating the earth and the oceans, and most will be radiated into the universe.
A: First of all, gravity does continually accelerate the air molecules. I don't see how this could make them lose their momentum.
What is the net effect of gravity on the atmosphere? Simple, gravity prevents the atmosphere from flying off in space, and instead it keeps it comfortably wrapped around our planet!
The reason why the atmosphere is still thick after billions of years is because you have two net effects on the air molecules, gravity, which keeps it as close as possible to the ground, and inertia, who has the opposite net effect. So as long as the molecules do not slow down they "orbit" our planet.
The reason is the same as why is the moon orbiting the Earth after billions of years. There's a balance between the kinetic energy of the moon and the gravitational potential energy - or a balance between gravity and inertia.
The other answers give you a summary explanation of what determines the temperature of the atmosphere and hence its molecules' average velocity. The reality is way more complicated as the temperature of the atmosphere is not constant with height and you have to take into account many more factors like varying pressure, convection and so on. Modelling the Earth's atmosphere accurately is very complicated.
In conclusion the basic mechanisms are outlined above. I hope they answer your question.
A: The sun keeps the earth warm. Without it, the atmosphere would freeze solid.
A: Hydrostatic balance...the vacuum of space wants to suck all the molecules of air out but it's perfectly counter balanced with the gravity of Earth...all the while we keep spinning and rotating thousands of miles per hour in space around a giant nuclear reactor just waiting to destroy us all :)
A: Gravitational force is the weakest of all the natural fundamental force. After ascending to certain height due to thermal energy of expansion caused by the Sun's heating it and its own KE of collisions among other gas molecules, equilibrium is established between the said two forces . Moons Gravity also contributes to the ascent of the gases molecules against Earth's G.
A: It is because the force of attractions between the particles become strong as they get cold by law of thermodynamic so the move towards earth to get heat. And when they got heat there force 9f attractions become loose and act as single molecule so they move upward
A: "Ideal gas"
If we consider an ideal gas, the molecules of which do not collide, then each of them behaves as a tennis ball, studied it Physics 101: it falls to the ground and bounces back, performs a parabolic trajectory, bounces again, etc. In this sense the molecules do fall to the ground - they can't settle, because their energy is conserved.
Real world
What the above naïve picture misses is the collisions between molecules, which are implied even in the ideal gas - as they are responsible for the establishment of the thermodynamic equilibrium (if molecules are truly non-interacting, then their energy is conserved and the energy distribution remains the same as it was in the beginning, as can be seen from the first paragraph.) Still, in a sufficiently rarefied gas, molecules do hit the ground.
This is not the case in air, where the mean free path is about a hundred of nanometers. Thus, a molecule that is falling down would be scattered and reverse its velocity. This shortness of the mean free path that justifies the hydrodynamic approximation, in which volumes of hot air rise, as if confined in a balloon (rather than passing through the cold air).
Water droplets do fall
Let us however think instead of molecules of water droplets, suspended in the air. When the droplets are small and dense, they behave pretty much like an ideal gas, and remain suspended in the air. However, as the droplets collide, they merge and grow, becoming rarefied enough to actually fall... and then it rains!
