This talk will address the preferred mass and time for galaxy formation, in dark-matter haloes similar to that of the Milky way but when the Universe was a few Gigayears old. It is proposed that this is due to the interplay between two mechanisms, first supernova feedback that removes gas from the galaxy, and second hot gas in the deep potential well of massive haloes that suppresses cold gas supply to the galaxy, the two being effective in galaxies of lower and higher masses respectively. Cosmological simulations reveal that the same mechanisms are responsible for a robust sequence of events were galaxies undergo a dramatic gaseous compaction, sometimes caused by mergers, into a compact star-forming “blue nugget”. This triggers inside-out quenching of star formation, which is maintained by a hot massive halo aided by black-hole feedback, leading to todays passive elliptical galaxies. The blue-nugget phase is responsible for drastic transitions in the main galaxy structural, kinematic and compositional properties. In particular, the growth of the black hole in the galaxy center, first suppressed by supernova feedback when below the critical mass, is boosted by the compaction event and keeps growing once the halo is massive enough to lock the supernova ejecta by its deep potential well and the hot halo. These events all occur near the same characteristic halo mass, giving rise to the highest efficiency of galaxy formation and black-hole growth at this magic mass and time.