The stock market means all stock exchanges within a geographical region. For example, the US stock market or the Indian stock market.
Within each market, there are multiple stock exchanges.
A stock exchange is like a supermarket for shares. Think of the NASDAQ and New York Stock Exchange as Sam’s Club and Costco. They sell similar things and they have to compete for customers. The more trades they process, the more money they make.
Any share you want to buy or sell will be listed on an exchange. As the buyer (or seller), it makes no difference to you which one it is. When you go online and place your order, the computer will route your trade to the correct exchange within seconds.
Exchanges pair up buyers and sellers (just like eBay). When shares are for sale, they have an asking price, called the “ask price.”
Buying shares is like being the bidder on eBay, so the buyer has to pay a “bid price.”
There will always be a gap between the two (usually a few pennies). This is called the “spread.” That spread is how the exchanges make money. It’s their commission.