An entire company is not divested, or sold, through an IPO, or Initial Public Offering. The current owners--shareholders--of the company sell part of their shares on the public market. The general public, major financial houses and investment firms buy the shares. Current management continues to operate the company. When a company merges, or is acquired, by another company, the current owners are paid and may or may not remain with the company. In some cases, the owners have nothing more to do with the management or operations. In others they continue either as an employee, rather than owner, or in a consulting capacity.
Expenses are involved when you go public or sell your company. The costs are higher with an IPO. An investment banking firm will charge an initial retainer and a percentage of the funds raised through the IPO. A business broker that sells your company, whether it's merged with another company or is acquired by that company, is less expensive than an investment banking firm. Legal fees are required in both instances. For an IPO, required legal documents, a prospectus, is filed with the Securities and Exchange Commission. For a sale, there needs to be a contract, which is much simpler and less time consuming that a prospectus.
Finding a buyer may take months, or even a year or longer, but once the buyer is found, the deal can close within 30 days or less, depending on how much due diligence the buyer requires. An IPO takes quite a bit longer. The prospectus is reviewed by the Securities and Exchange Commission. If there are discrepancies, or the SEC has questions, the company must respond. The time between submitting the prospectus and selling shares varies widely but ranges between three and six months. That doesn't include the time required to prepare the prospectus.
The buyer may place restrictions on the owner of the business, such as agreeing not to set up a competing business, but these restrictions are negotiable. After an IPO, pre-IPO shareholders usually agree not to sell their post-IPO stock for a period of time in the prospectus. There's also a quiet time of 40 days mandated after the stock has been offered to the public. Theoretically it's to let the market determine the stock's price without hype from the company's management. A public company must file financial statements on a quarterly and yearly basis that show the inner workings of the company. While the public company doesn't give away trade secrets in these filings, it's valuable to competitors to know how the competition is doing.
While the company shareholdersrs, in conjunction with the investment bankers, may set an initial price for the stock, the final price is unknown. It may end up quite a bit lower or higher. External factors such as the economy, technological advances, even announcements from competitors affect the price. The volume of the shares offered is not a guarantee either. IPOs can and have been pulled before the stock goes public. When a company is sold, the owners know how much money they'll be receiving and when.