On the stock market when you buys shares I'm guessing it's from the company. However, when you want to buy or sell shares can you always do this? Do you need to wait for someone to buy them in the stock exchange or are the company obliged to sell them back to you?
In the old days, you had to give your order to a broker who was typically a member of a stock exchange like the NYSE. It was a membership that only allowed members to trade. Trading took place on the floor physically at a trading post, which was run by a specialist or dealer. The specialist would have special rights and obligations that allowed them to control the trading of the trade book, where all the orders were aggregated.
If you wanted to purchase, say 1000 shares of GM stock, you would call in an order for a $5.00 bid for 1000 shares. Your order would in some way make it to a clerk in a booth on the edge of the floor. The clerk would relay the order to the floor broker, either physically on paper, by telephone, or with hand signals(which were similar to sign language, and rather complex). The broker would then enter the trading crowd in front of the specialist...
Let's say there were 2 other brokers and the spec in the crowd. Each broker was offering 400 shares at $5.00, for a total of 800. Your broker would go in and ask where he could purchase 1000k shares. The dealer would say there're 800 shares at $5, and that he'd clean you up on the balance, meaning sell you 200 shares that he owned(the other brokers would likely be representing other customers, not their own accounts). Your broker would pay $5.00 for 1000 shares. To do this all parties would exchange badge numbers and give-ups. All members on the floor had a badge number to match them to their trades, as there were many transactions per day, perhaps thousands, performed by most members. Your give-up would be the symbol assigned to the clearing broker, of which there were many, such as Credit Suisse, BofA, JPM, Morgan Stanley, etc. So, your broker would say "giving up NFS" for example. The other guys would be familiar with him and his badge # and not have to ask. He would get the give-up of the 2 brokers and specialist and write that info along with the quantity each, and price, on the ticket. He would phone in a trade confirmation to the booth, which would eventually make it back to the original buyer. For example, it could go from broker on the floor to clerk in the booth to NFS office in downtown Manhattan to regional office from where you placed the trade back to you in your kitchen, more or less. A runner would take the tickets to the booth, and at the end of the day all trades were matched and confirmed in the DK room(Don't Know) to identify and correct potential errors.
The trades you do are not with the company that issues the stock, but with 3rd parties who own shares. That could mean institutional holders like a mutual fund, or individuals like yourself. As I mentioned before, dealers had special rights as well as obligations. One of those obligations is to provide liquidity. So, if you want to buy or sell and there is no one to trade with, you can always trade with the specialist. However, they don't have to meet you on price. In the GM example, let's say you wanted to buy 1000 shares, and there were no orders to sell on the floor. The dealer would say, "I'll sell you 1k at 5 1/4, or $5.25 (trading was in fractions until 2000, I think). Then, if you wanted them, you'd have to pay $5.25. If you didn't want to pay that much, you would have to wait for a seller to come in who wanted to buy them, which may or may not happen by the end of the day. Most stock orders are day orders, where they are good all day long, but canceled at the close of the market. If you want to place the order again, you have to do it the next day.
It's mostly the same today, except now that's it's computerized. Your broker is a computer that trades with other computers, which makes it much faster and less expensive.