A direct numerical simulation study of self-similar compressible flat-plate turbulent boundary layers (TBLs) with pressure gradients (PGs) has been performed for inflow Mach numbers of 0.5 and 2.0. All cases are computed with smooth PGs for both favourable and adverse PG distributions (FPG, APG) and thus are akin to experiments using a reflected-wave set-up. The equilibrium character allows for a systematic comparison between sub- and supersonic cases, enabling the isolation of pure PG effects from Mach-number effects and thus an investigation of the validity of common compressibility transformations for compressible PG TBLs. It turned out that the kinematic Rotta–Clauser parameter $\unicode[STIX]{x1D6FD}_{K}$ calculated using the incompressible form of the boundary-layer displacement thickness as length scale is the appropriate similarity parameter to compare both sub- and supersonic cases. Whereas the subsonic APG cases show trends known from incompressible flow, the interpretation of the supersonic PG cases is intricate. Both sub- and supersonic regions exist in the boundary layer, which counteract in their spatial evolution. The boundary-layer thickness $\unicode[STIX]{x1D6FF}_{99}$ and the skin-friction coefficient $c_{f}$, for instance, are therefore in a comparable range for all compressible APG cases. The evaluation of local non-dimensionalized total and turbulent shear stresses shows an almost identical behaviour for both sub- and supersonic cases characterized by similar $\unicode[STIX]{x1D6FD}_{K}$, which indicates the (approximate) validity of Morkovin’s scaling/hypothesis also for compressible PG TBLs. Likewise, the local non-dimensionalized distributions of the mean-flow pressure and the pressure fluctuations are virtually invariant to the local Mach number for same $\unicode[STIX]{x1D6FD}_{K}$-cases. In the inner layer, the van Driest transformation collapses compressible mean-flow data of the streamwise velocity component well into their nearly incompressible counterparts with the same $\unicode[STIX]{x1D6FD}_{K}$. However, noticeable differences can be observed in the wake region of the velocity profiles, depending on the strength of the PG. For both sub- and supersonic cases the recovery factor was found to be significantly decreased by APGs and increased by FPGs, but also to remain virtually constant in regions of approximated equilibrium.