Sir Isaac Newton proposed the law of gravitation. It is stated as follows, "Every particle of matter in the universe attracts every other particle with a force that is directly proportional to the product of the masses of the particles and inversely proportional to the square of the distance between them. " Thus the gravitational force = (G(m1)(m2))/ r squared. G is the gravitational constant, m's are the masses of two separate particles, r is the distance between the two particles.
G= 0.00000000006672 Nm^2kg^2. Because G is so small, the gravitational attraction between two small bodies is VERY small. The gravitational force becomes more significant when a body is very large, such as the Earth. Since the Earth has a large mass, it will have a relatively large gravitational force. All objects much smaller than the earth will accelerate toward the Earth's center of mass (toward the Earth's core).
It is gravity that holds the atmosphere is place. If the Earth's mass was much smaller (i.e. 1/4th the present size), the gravitational acceleration would not be large enough to hold the density of an atmosphere that we have now. Take for example Mars. Mars has a mass that is much less than that of earth and is only able to hold an atmosphere than is 6 millibars of pressure compared to the earth's 1000 mb atmosphere. Larger planets have higher escape velocities. Escape velocity is the minimum speed an object must have to escape a planet's gravitational field. Most gases are not able to escape Earth's gravitational field, thus the mass of the atmosphere remains fairly constant over time. Gravity is accelerating the gases of the atmosphere toward the center of the earth. Obviously, the gasses are not able to go through the earth's crust. Therefore, the majority of the gas compresses itself near the earth's surface. This is why the atmosphere is most dense in the low levels of the atmosphere.
There is also an upward directed pressure gradient force that acts on gases. Since lower pressure occurs aloft, gases near the surface are pulled by the upward directed pressure gradient force. The upward directed PGF and the downward directed gravitational force come into balance. This is called hydrostatic equilibrium. Since the earth is not perfectly round, there are slight variations in crust density and the earth rotates, gravity varies slightly with sea-level latitude. Gravity increases slightly with increasing latitude. The difference in gravity between the equator and pole is about 0.034 m per seconds squared. Gravity also decreases slightly with increasing altitude. This is because the r term (distance between two bodies) becomes larger when an object is moved further away from the center of the earth. When r increases, the gravitational force decreases.