A marketplace, not a vault
A stock exchange is simply a place where buyers and sellers meet. You are almost never buying from the company itself — you are buying from another investor who wants to sell. The exchange matches you up and records the trade.
The "price" you see is just the most recent price someone agreed to pay. It updates every time a new trade happens, which during market hours can be many times per second.
How a price is set
At any moment there is a highest price buyers are willing to pay (the bid) and a lowest price sellers will accept (the ask). A trade happens when those two meet. More eager buyers than sellers push the price up; the reverse pushes it down. This constant tug-of-war is called price discovery.
Indexes: the market at a glance
You will hear about the S&P 500, Nasdaq, and others. These are indexes — baskets that track many companies at once so you can see how a whole slice of the market is doing, not just one stock. When people say "the market was up today," they usually mean an index like the S&P 500.