When a company makes an Initial Public Offer (IPO), the proceeds of such IPO goes to the company issuing the IPO. This is the time the shares are said to be part of the ‘Primary market’.
Once a share gets listed on the Stock Exchange, its said to be part of the ‘Secondary market’ the stock-money exchange happens between public investors.
To cite an example, assume company ‘X’ came up with an IPO and if you subscribe to this IPO and get allotment, the money that you pay would go to company ‘X’ [primary market].
Once the shares are allotted to you and the shares are listed on the Stock Exchange, you are free to sell it on the Stock Exchange [secondary market] where the stock-money exchange happens between you and the buyer of the share.