We devise and exploit a data-driven, semi-empirical framework of galaxy formation and evolution, coupling it to recipes for planet formation from stellar and planetary science, to compute the cosmic planet formation rate, and the properties of the planets’ preferred host stellar and galactic environments. We also discuss how the rates and formation sites of planets are affected when considering their habitability, and when including possible threatening sources related to star formation and nuclear activity. Overall, we conservatively estimate a cumulative number of some 1020 Earth-like planets and around 1018 habitable Earths in our past lightcone. Finally, we find that a few 1017 are older than our own Earth, an occurrence which places a loose lower limit a few 10−18 to the odds for a habitable world to ever host a civilization in the observable Universe.