We mostly trade stocks through brokers and stock exchange but hardly care of the process that underlies below. Let's look into the whole process of how stock market works?
Initially when a company gets registered as public limited company they get the opportunity to distribute their shares a part of their company into the stock market. But how the process works. First of all the company decides what percentage of their company capital they want to raise from shares. Next they determines in what number of shares do the amount should be distributed. Let the company decides they want to raise Amount X is is Z percent of their total capital to be raised to be distibuted in N number of shares. In that case the price of each share they release would be an amount of X / N. Then N number of shares with amount X / N for each share is released through the market as IPO (Initial Public Offerring). Lets understand how it works.
The companies need to discuss the same and facilitate it through stock exchange. In India there are two stock exchanges NSE and BSE. The stock exchange is regulate by SEBI rules. Now the stock exchange does the work to forward this IPO to the stock brokers. Stock brokers need to register themselves with the stock exchange and works as an intermediary between company, stock exchange and investors. They takes some commission on each sale from investors for their working. The IPO is forwarded from the stock exchange through the stock brokers to the market for investors. Once all of the shares in IPO is bought by investors in vivid numbers the amount is transferred to the company account with some charges in between by stock exchange. In this way the company raises the capital from the market. This is the only time the company gets monetarily involved in the whole process. The whole facilitators together is called the stock market. This is called primary market. Now once all IPO are released the stock enters the secondary market.
What happens in the secondary market? Now all the shares are assigned to some of the investors. From time to time the company has to submit their balance sheets and other valuations to the stock exchange which includes it's total amount it has from profit or loss and other means like from trade of shares itself etc. The stock exchanges makes a valuation for the price of the share on the basis of these things and determine the price of the share at that point. Now there can be some good news or bad news for the company spread into the market which can project it's future financial status. So on that basis shares also get bought and sold in the market which further changes its valuation. How it works?
For example a company has loss of 10% in the financial term. So the share price X / N will also decrease an amount of 10%. On addition to it an news was spread that the company will go further financial loss in near future. Investors will now look to take off their money from the shares of the company. Let an investor with N / 10 amount of shares sells its shares. Then the valuation of the company will further decrease by an amount of N / 10 multiplied by price of each share. Thus new valuation of the company will be 90X/100 - 9X/100 = 81X/100. This will be the new price of the shares. Thye next buyer will buy this share at that price. Similar will be the case for profit also the price of share will increase. Now when someone sells there must be a buyer. Now when an investor buys a share the total valuation increases again increasing the price of share.
The persons who spread good or bad news are called bull or bear respectively. Now what happens when the price of share keeps on decreasing and there is no more buyer. Now people willing to sell their share have to wait until there is a buyer which can be indefinite. But if in between the company incurred heavy losses and gets closed then the shareholder will lose all of his money invested in share for the company. But if the company keeps running normally then the process of selling and buying along with its valuation and price of shares will keep on flowing as mentioned previously. In the process the investors can gain profit or incurr losses on each trade and the process continues in the market.
This is how in detail the whole process works in share market.