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 colour-selected carbon stars. We find the median absolute magnitude and the dispersion, in the J band, for the Large and the Small Magellanic Clouds (LMC/SMC) to be, respectively, (M_J_=-6.284+/-0.004 and {sigma}=0.352+/-0.005) and (M_J_=-6.160+/-0.015 and {sigma}=0.365+/-0.014). The difference between the MC may be explained by the lower metallicity of the SMC, 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 error-weighted mean C magnitude of the MC are equal. Thanks to the next generation of telescopes (JWST, ELT, and TMT), carbon stars could be detected in MC-type galaxies at distances out to 50-60Mpc. The final goal is to eventually try and improve the measurement of the Hubble constant while exploring the current tensions related to its value.