The idea of vacuum, or void as it was called in antiquity, did not originally come from considerations about air and Earth's atmosphere, but rather from natural philosophic speculations about the nature of Cosmos, which predate discovering the relation between void and air. Presocratic philosophers starting with Thales considered nothing or void speculatively, but rejected it as a physical possibility, until the atomists (c. 450 BC), most notably Leucippus, Democritus, and later Epicurus, embraced it, and developed a systematic view of nature based on it. Their entire universe consisted of atoms and void in between, air was a particular arrangement of atoms.
"These ancient atomists theorized that the two fundamental and oppositely characterized constituents of the natural world are indivisible bodies—atoms—and void. The latter is described simply as nothing, or the negation of body. Atoms are by their nature intrinsically unchangeable; they can only move about in the void and combine into different clusters. Since the atoms are separated by void, they cannot fuse, but must rather bounce off one another when they collide."
They also postulated that "there is an infinite number of worlds, some like this world, others unlike it" (Epicurus), separated by the void, and confined earth, sea, air, etc. to our world. However, they also saw the fixed stars as a part of our world, in fact the outer edge of it.
That air was a substance might have been demonstrated by a presocratic Empedocles (c. 490–430 BC) with a glass tube called hydra, but this account is controversial, and Aristotle's supposed demonstration by weighing an inflated bladder is known to be an artifact. It was only much later that Galileo measured air weight, and suggested that existence of a vacuum can be tested in experiments. One year after Galileo's death, in 1643, his assistant Torricelli famously gave the experimental proof he suggested, and invented the barometer to measure atmospheric pressure. Thus, it became possible to measure atmospheric pressure at different heights (qualitatively, 'thinning' of the air with altitude was observed much earlier). Pascal performed a public demonstration at a fair of the effects of altitude on a column of mercury, and surmised existence of a vacuum above the atmosphere in 1648. And soon Hooke presented an estimate of how far the atmosphere extends in Micrographia (1665), after conjecturing the inverse square law for gravity.
The presocratic tradition culminated in Aristotle (384-322 BC) postulating that "nature abhors vacuum", which is how he explained why water rises in a suction pump, the phenomenon that Torricelli explained using the concepts of atmospheric pressure and air vacuum. But it does not mean that he believed in air stretching out into the whole Cosmos. According to Aristotle the natural places of "four elements", earth, water, air and fire, are confined to the sublunar sphere. Everything above the moon is permeated by a "nobler" substance, ether.