Gases Near A Planet:
Now visualize the gaseous shroud which surrounds a reasonably big planet, like our own Earth. Gravitation attracts several gases from the surrounding space. The other gases are evicted from the planet's interior during volcanic activity. Still other gases are generated by the biologic activities of plants and animals, when the planet harbors life. In the situation of Earth, some gases are generated by industrial activity and by the combustion of fossil fuels.
All the gases in the Earth's atmosphere tend to diffuse, though as there is an necessarily unlimited quantity of "outer space" and only a limited amount of gas, and since the gravitational pull of the Earth is more nearer to the surface than far out in space, the diffusion occurs in a different way than inside a small container. The maximum concentration of gas molecules (particle density) occurs near the surface, and it decreases with raising altitude which is as shown in figure below. The same is true of the number of kilograms per meter cubed of the environment, that is, the mass density of the gas.
Figure: (a) Distribution of gas inside a container. (b) Distribution of gas about a planet with an atmosphere. (c) Distribution of gas in a star is forming. Darkest shading indicates highest concentration.
On the big scale of the Earth's atmosphere, so far another effect takes place. For a given number of atoms or molecules per meter cubed, few gases are more massive than others. Hydrogen is the least massive; helium is also light. Oxygen is more massive, and carbon dioxide is more massive still. The most massive gases tend to sink toward the surface, while the least massive gases rise up high, and some of their atoms run away into outer space or are not captured permanently by the Earth's gravitation.
There are no different boundaries, or layers, from one kind of gas to another in the atmosphere. Rather, the transitions are vague and gradual. This is good, as if the gases of the atmosphere were stratified in a defined way, we would have no oxygen down here on the surface. Rather, we'd be smothered in some noxious gas like carbon dioxide or sulfur dioxide.