Our goal in this paper is to derive a carbon-star luminosity function that will eventually be used to determine distances to galaxies at 50-60 Mpc and hence yield a value of the Hubble constant. Cool N-type carbon stars exhibit redder near-infrared colours than oxygen-rich stars. Using Two Micron All Sky Survey near-infrared photometry and the Gaia Data Release 2, we identify carbon stars in the Magellanic Clouds (MC) and the Milky Way (MW). Carbon stars in the MC appear as a distinct horizontal feature in the near-infrared ((J − K s ) 0 , M J ) colour-magnitude diagram. We build a colour selection (1.4 < (J − K s ) 0 < 2) and derive the luminosity function of the colourselected carbon stars. We find the median absolute magnitude and the dispersion, in the J band, for the Large Magellanic Cloud and the Small Magellanic Cloud to be, respectively, ( MJ = −6.284 ± 0.004, σ = 0.352 ± 0.005) and ( MJ = −6.160 ± 0.015, σ = 0.365 ± 0.014). The difference between the MC may be explained by the lower metallicity of the Small Magellanic Cloud, but in any case it provides limits on the type of galaxy whose distance can be determined with this technique. To account for metallicity effects, we developed a composite magnitude, named C, for which the errorweighted mean C magnitude of the MC are equal. Thanks to the next generation of telescopes (JWST, ELT, TMT ), carbon stars could be detected in MC-type galaxies at distances out to 50-60 Mpc. The final goal is to eventually try and improve the measurement of the Hubble constant while exploring the current tensions related to its value.