When a company decides to go public, it offers its shares to the general public for the first time through an IPO. Investors can buy these shares through stock exchanges.