The regular ABX3cubic perovskite structure is composed of close-packed AX3layers stacked along the 〈111〉 axis. An equivalent hexagonal close-packed network can also be formed, in addition to a series of intermediate polytype sequences. Internally, these correspond to combinations of face- and corner-sharing octahedral chains that can dramatically alter the physical properties of the material. Here, we assess the thermodynamics of polytypism in CsPbI3and CsPbBr3. The total energies obtained from density functional theory are used to paramaterize an axial Ising-type model Hamiltonian that includes linear and cubic correlation terms of the pseudo-spin. A genetic algorithm is built to explore the polytype phase space that grows exponentially with the number of layers. The ground-state structures of CsPbX3polytypes are analysed to identify features of polytypism such as the distinct arrangements of layers and symmetry forbidden sequences. A number of polytypes with low ordering energies (around thermal energy at room temperature) are predicted, which could form distinct phases or appear as stacking faults within perovskite grains.