Bandgap engineering is one of the keys to practical applications of ZnO. Using ternary ZnMeO (Me=Be, Mg, Cd, etc.) alloys to regulate the bandgap of ZnO has been widely studied. Alloying ZnO with CdO to form CdxZn1-xO is an effective way to narrow down the bandgap of ZnO. With its narrower bandgap, CdxZn1-xO is a promising candidate for fabricating optoelectronic devices operable in the UV-visible wavelength region. In this work, we study the thermodynamic properties of CdxZn1-xO alloys of both wurtzite (WZ) and rock salt (RS) structures by first-principles calculations based on density functional theory (DFT) combined with the cluster expansion approach. The effective cluster interactions (ECIs) fitted formation energies agree well with the DFT-calculated formation energies for different compositions and structures correspondingly, validating the cluster expansion approach in calculations of the formation energy for CdxZn1-xO alloys. It is found that, for both WZ-CdxZn1-xO and RS-CdxZn1-xO alloys, the ECIs involve pair, triplet and quadruplet interactions: the pair interactions are dominant and contribute mostly to the formation energy. The first-and second-neighbor pair interaction parameters of WZ-CdxZn1-xO are positive, which indicates a tendency of ordering in WZ-CdxZn1-xO. For RS-CdxZn1-xO alloys, the nearest-neighbor pair interaction is negative, indicating a tendency to phase separation. The dominant positive second-neighbor pair interaction, however, appears to favor the ordering tendency. For both the WZ-CdxZn1-xO and RS-CdxZn1-xO alloys, the calculated formation energy of most structures is positive in the whole composition range, except for WZ-CdxZn1-xO with Cd concentrations of 1/3 and 2/3. Then, the crystal and electronic band structures of the metastable WZ-Cd1/3Zn2/3O and WZ-Cd2/3Zn1/3O are calculated. It turns out that both lattice constants a and c increase while the value of c/a and the bond angle of OZn(Cd)O decrease with increasing Cd concentration in the WZ-CdxZn1-xO alloys. Analyses of the band structures, densities of states (DOSs) and partial densities of states of WZ-CdxZn1-xO alloys reveal that the valence band maximum (VBM) is determined by O-2 p states and the conduction band minimum (CBM) stems from the hybrid Cd-5 s and Zn-4 s orbital. The VBM rises while the CBM declines, leading to the decrease of the bandgap of WZ-CdxZn1-xO with increasing Cd concentration. At finite temperatures, the thermal stability of the solid-state system is determined by Gibbs free energy. The bimodal curve, which indicates the equilibrium solubility limits as a function of temperature, can be calculated by the common tangent approach from the Gibbs free energy. The critical temperatures, above which complete miscibility is possible for some concentrations, are 1000 and 2250 K for WZ and RS phases, respectively. The higher critical temperature implies that it is more difficult to form RS-CdxZn1-xO than to form WZ-CdxZn1-xO. Finally, the phase diagrams of WZ-CdxZn1-xO and RS-CdxZn1-xO are derived based on calculations of the Gibbs free energy. At 1600 K, the solubility of Cd in WZ-ZnO amounts to 0.13, while the solubility of Zn in RS-CdO limits to only 0.01, indicating that it is much easier to incorporate Cd into WZ-ZnO than to incorporate Zn into RS-CdO.