Formation of the atmosphere