Why is space a vacuum? Also, why isn't the air from the Earth escaping due to the vacuum in space? The ozone layer is only gas and a magnetic field, so why doesn't the air escape from Earth into space?
You can think of planets like wells or deep holes in the ground (gravity wells). Denser things fall to the bottom (rocks), less dense things rest on top of that (water), even less dense things on top of that (air), and finally the least dense thing on top of everything (vacuum).
The air, for the most part, isn't leaving the planet for the same reason the water isn't flying out of the ocean, gravity is holding it down.
It's important to remember that space doesn't suck. It's not that kind of vacuum. There is not a force pulling things into space in the same way there is not a force pulling air out of a hole in a balloon.
The typical speed of an air molecule is a few hundred meters per second, while escape velocity from Earth is over 10,000 meters per second. So almost all the air molecules just fall back down. They're affected by gravity just like everything else!
We do lose some air molecules this way, though. In particular, hydrogen and helium are lighter, so they move faster and escape significantly more often. This is why our atmosphere has very little of those two. But Jupiter, which has much stronger gravity, has an atmosphere mostly of hydrogen and helium.
Air fails to escape into space for the same reason you fail to: gravity. As noted in Kevin's answer, occasionally some do get going fast enough to escape. You would too, if enough stuff hit you hard enough. :)
Space is a vacuum (for some definition of vacuum), because vacuum is simply the absence of air/gas pressure, and there aren't enough gas molecules in space to create a noticeable pressure.
That said, note that there are particles in space; they are moving, and they do exert pressure on things they hit. See e.g. solar wind and heliopause. So depending on what/where you're measuring, space is far from a vacuum.
To give a simple answer:
Space is an (almost) vacuum, since there is simply not enough air left to be there.
Where did all this air go? Due to gravity the air is attracted to large objects, like planets and exactly this gravity is also keeping the air close to the object - preventing it from "flowing back into space"