Rayleigh–Bénard (RB) convection with free-slip plates and horizontally periodic boundary conditions is investigated using direct numerical simulations. Two configurations are considered, one is two-dimensional (2-D) RB convection and the other one three-dimensional (3-D) RB convection with a rotating axis parallel to the plate, which for strong rotation mimics 2-D RB convection. For the 2-D simulations, we explore the parameter range of Rayleigh numbers $Ra$ from $10^{7}$ to $10^{9}$ and Prandtl numbers $Pr$ from $1$ to $100$. The effect of the width-to-height aspect ratio $\varGamma$ is investigated for $1\leqslant \varGamma \leqslant 128$. We show that zonal flow, which was observed, for example, by Goluskin et al. (J. Fluid. Mech., vol. 759, 2014, pp. 360–385) for $\varGamma =2$, is only stable when $\varGamma$ is smaller than a critical value, which depends on $Ra$ and $Pr$. The regime in which only zonal flow can exist is called the first regime in this study. With increasing $\varGamma$, we find a second regime in which both zonal flow and different convection roll states can be statistically stable. For even larger $\varGamma$, in a third regime, only convection roll states are statistically stable and zonal flow is not sustained. How many convection rolls form (or in other words, what the mean aspect ratio of an individual roll is), depends on the initial conditions and on $Ra$ and $Pr$. For instance, for $Ra=10^{8}$ and $Pr=10$, the aspect ratio $\varGamma _r$ of an individual, statistically stable convection roll can vary in a large range between $16/11$ and $64$. A convection roll with a large aspect ratio of $\varGamma _r = 64$, or more generally already with $\varGamma _r \gg 10$, can be seen as ‘localized’ zonal flow, and indeed carries over various properties of the global zonal flow. For the 3-D simulations, we fix $Ra=10^{7}$ and $Pr=0.71$, and compare the flow for $\varGamma =8$ and $\varGamma = 16$. We first show that with increasing rotation rate both the flow structures and global quantities like the Nusselt number $Nu$ and the Reynolds number $Re$ increasingly behave like in the 2-D case. We then demonstrate that with increasing aspect ratio $\varGamma$, zonal flow, which was observed for small $\varGamma =2{\rm \pi}$ by von Hardenberg et al. (Phys. Rev. Lett., vol. 15, 2015, 134501), completely disappears for $\varGamma =16$. For such large $\varGamma$, only convection roll states are statistically stable. In-between, here for medium aspect ratio $\varGamma = 8$, the convection roll state and the zonal flow state are both statistically stable. What state is taken depends on the initial conditions, similarly as we found for the 2-D case.