How does a company decide when to go public, and what factors impact that decision? What should consumers understand before investing in any company, whether during an IPO or in the secondary market?

How does a company decide when to go public, and what factors impact that decision? What should consumers understand before investing in any company, whether during an IPO or in the secondary market?