The present-day Earth with its innumerable life forms is a product of cosmic evolution starting with the formation of our galaxy and the dense gas clouds within it, and proceeding through the contraction of one of those clouds about 4.6 Gyr ago, first into filaments and then one or more protostellar disks, planets, and central stars, one of which was our Sun. Radioactive debris from a massive nearby star was included. The planets themselves formed through coagulation, accretion, and fragmentation of solid bodies. Habitability depends on a delicate balance between disk accretion by gravity and dispersal by the central star, which determine the size of the planet and its gaseous envelope, combined with a long period of stellar radiation, which has to disperse this envelope but leave a hospitable secondary atmosphere. The final step toward life involves even more complexity as self-replicating bio-molecules form with ever increasing stability.