You always can buy shares of stock thanks to the existence of stock exchanges. These are centralized places where buyers and sellers come together to transact their business in a fair, organized and regulated way.
Stock trading is a continuous auction market. Every transaction reflects the price that a buyer and seller agree upon. If they can’t agree, there is no trade. Everything is available at the right price. If a buyer cannot find shares at a particular price, he always can increase his bid until somebody decides that the bid is sufficiently high and sell at a profit. If a seller cannot find a buyer for his shares at a particular price, he always can lower the asking price until somebody decides that it is sufficiently low to warrant a bargain purchase.
Specialists and Market Makers
The New York Stock Exchange has a system of specialists whose job is to maintain orderly markets in specific stocks. Most of the time, specialists trade for their own accounts, buying and selling shares as orders come in. Nasdaq market makers are not required to maintain markets in particular stocks, but they essentially do that. Specialists and market makers always have enough shares in their inventory to sell to you, but even if they run out of shares, they always can borrow them from someone else. These professionals make money when they trade, so they will always find a way to accommodate a buy order at a small profit.
Taking Both Sides of an Order
An institutional trader in a particular stock often takes both sides of a trade. For example, he may simultaneously offer to buy XYZ at $20.10 and sell it at $20.20. The 10 cent per share difference, called spread, is his profit. When your order to buy 100 of XYZ comes in, the trader will sell you the shares for $20.20. Half an hour later, an order to sell 100 XYZ may come in from another investor and the trader will buy the shares from him for $20.10, making his 10 cents a share profit on the two transactions. Both you and the other investor wanted the same thing -- immediate execution at a reasonable price -- but were a half hour apart. The trader provided a service by accommodating both orders immediately and cleared a small profit. The trader only has to balance his books at the end of the day, so he is able to sell a stock first and buy it second.
Role of Wall Street
Wall Street lives off selling stocks to investors. If there is demand, brokers will find shares to sell, or investment bankers will create them. Brokers may talk insiders or customers into selling their holdings; investment bankers may find a new company to take public (sell its stock in an initial public offering) or advise an existing company to sell more stock in a secondary offering.