The atmosphere is just the gases surrounding Earth or any other planet in the form of layers. What keeps these layers intact is the gravity of a planet. When the planets were forming, the gases being released from volcanic activity and interior of planets led to the formation of the atmosphere of the planets which were able to retain it through gravity, basically, gases are the constituents of a planetary atmosphere. The atmosphere of a planet depends on many factors like mass, radius of a planet, escape velocity of particles and temperature of constituent gases.
The mercury doesn’t have any atmosphere because the velocity of the particles being released from its interior or during volcanic activity while it was formed, is/was more than the escape velocity. Escape velocity is the velocity required by the particles or rockets to escape from the planet’s gravitational influence into space. Earth has an atmosphere because it is massive enough to retain one with the help of its gravity. It is the most massive of the inner planets. Mars has a very thin atmosphere which mostly has carbon dioxide. It is said that it lost its atmosphere during initial bombardments. Jupiter is way more massive so it can retain more of it (atmosphere) and thus, the atmosphere extends to greater heights if we compare it to Earth.
The atmosphere is just piling up of the particles and as we move up towards space it becomes thin. A point comes where, one can say, the transition from the atmosphere to space occurs.It is a gradual transition, we can’t just define a particular height where the atmosphere ends and space starts. Now in the case of Earth, according to NASA, if any NASA test pilot or astronaut is able to cross height of about 81 kilometers then they are awarded astronaut wings. Cool!!
One can question that why don’t just this atmosphere collapses into the Earth’s surface or just get washed away into space? Well, for the first case, take a balloon and try to press it holding it in one hand, you will feel pressure which will stop you to compress it further. The Same thing never lets Earth’s atmosphere collapse because it is not hollow, there is upward pressure because of the gaseous particles present near Earth’s surface, moreover, there are collisions going on between the particles.
In the second case, that’s why don’t it just gets washed away into space, gravity comes into play, which further depends on upon the mass of a planet. Particles that are moving slower than the escape velocity, which is 11.2 km/s (25,000 miles per hour) for Earth (ignoring air friction), are trapped in a “spherical cage”. Although some of them do an escape, but a number of gaseous particles being released from volcanic activity etc. balance the loss. As we move up towards space a point comes where the blue reflections, caused by particles present in the atmosphere (which leads to the blue color of the sky) lessen, as the number of particles present is decreased and we start seeing the black space.