SUMMARY The existence of a stably stratified layer underneath the core–mantle boundary (CMB) has been recently revived by corroborating evidences coming from seismic studies, mineral physics and thermal evolution models. Such a layer could find its physical origination either in compositional stratification due to the accumulation of light elements at the top or the core or in thermal stratification due to the heat flux becoming locally subadiabatic. The exact properties of this stably stratified layer, namely its size $\mathcal {H}_s$ and the degree of its stratification characterized by the Brunt–Väisälä frequency N, are however uncertain and highly debated. A stable layer underneath the CMB can have crucial dynamical impacts on the geodynamo. Because of the inhibition of the convective motions, a stable layer is expected to primarily act as a low-pass filter on the magnetic field, smoothing out the rapidly varying and small-scale features by skin effect. To investigate this effect more systematically, we compute 70 global geodynamo models varying the size of the stably stratified layer from 0 to 300 km and its amplitude from N/Ω = 0 to N/Ω ≃ 50, Ω being the rotation rate. We show that the penetration of the convective flow in the stably stratified layer is controlled by the typical size of the convective eddies and by the local variations of the ratio N/Ω. Using quantitative measures of the degree of morphological semblance between the magnetic field obtained in numerical models and the geomagnetic field at the CMB, we establish an upper bound for the stable layer thickness $\mathcal {H}_s\lt (N/\Omega )^{-1} \mathcal {L}_s$, $\mathcal {L}_s$ being the horizontal size of the convective flow at the base of the stable layer. This defines a strong geomagnetic constraint on the properties of a stably stratified layer beneath the CMB. Unless unaccounted double-diffusive effects could drastically modify the dynamics of the stable layer, our numerical geodynamo models hence favour no stable stratification atop the core.