The roles of magnetic field and temperature in thermodynamic formation of skyrmion crystals (SkXs) have not been well-revealed to date. Here we present a unified theory about SkX formation and its fascinating thermodynamic behaviours. A chiral film can have many metastable states with an arbitrary number of skyrmions up to a maximal value. A perpendicular magnetic field makes a film with Qm skyrmions the lowest energy state. Qm first increases with the magnetic field up to an optimal value and then decreases with the field. The film with the largest Qm at the optimal field is an SkX. Outside of a field window, states consisting of various stripes with low skyrmion number densities are thermal equilibrium phases while an SkX is metastable. Within the field window, SkXs are the thermal equilibrium states below the Curie temperature. However, the time to reach an SkX state from a stripy phase would be too long at a low temperature. This causes a widely spread false belief that SkXs are metastable and stripy states are thermal equilibrium phase at low temperature and at the optimal field. Our theory opens a new avenue for SkX manipulation and skyrmion-based applications.