Space is not very far away. Aircraft on long-haul flights travel at a height of about 10 km. The lowest layer of the atmosphere, the Troposphere, ends at about 15 km. The air in the layers above the troposphere is very thin indeed. Think of a place around 15 km (9 miles) from where you are. That's pretty much how near you are to space. All the waste gases people dump into the air are trapped in the thin layer of air around the Earth.
Molecules in the air include nitrogen and oxygen as well as water, carbon dioxide, ozone, and many other compounds in trace amounts, some created naturally, others the result of human activity.
In addition to gases, the atmosphere contains extras such as smoke, dust, acid droplets, and pollen.