The intense X-ray and UV emission of some active M stars has raised questions about the habitability of planets around M-type stars. We aim to determine the unbiased distribution of X-ray luminosities in complete, volume-limited samples of nearby M dwarfs, and compare them to those of K and G dwarfs. We have constructed volume-complete samples of 205 M stars with spectral type <=M6 within 10pc from the Sun, 129 K stars within 16pc, and 107 G stars within 20pc. We use X-ray data from Chandra, XMM-Newton, eROSITA, and ROSAT to obtain the X-ray luminosities of the stars. Our samples reach an X-ray detection completeness of 85%, 86%, and 80% for M, K, and G stars. The fractional X-ray luminosities, log(LX/Lbol), of the M stars show a bimodal distribution with one peak at around ~5, mostly contributed by early M stars (M0-M4), and another peak around ~3.5, contributed mainly by M4-M6 stars. The comparison of the different spectral classes shows that 63% of all M stars in our sample (80% of the M stars with spectral type <M4) have LX/Lbol values that are within the central 80% quantile of the distribution function for G stars. 55% of all M stars in our sample (and 72% of the M stars with spectral type <M4) have LX/Lbol less than 10 times the solar value. The X-ray activity levels of the majority (~>60%) of nearby M dwarfs no later than M6 are actually not higher than the typical (80% quantile) levels for G-type stars. The X-ray irradiation of habitable-zone planets around these stars should therefore not present a specific problem for their habitability.