The transverse momentum (pT) spectrum of prompt D0 mesons and their antiparticles has been measured via the hadronic decay channels D0→K−π+ and D‾0→K+π− in pp and PbPb collisions at a centre-of-mass energy of 5.02 TeV per nucleon pair with the CMS detector at the LHC. The measurement is performed in the D0 meson pT range of 2–100GeV/c and in the rapidity range of |y|<1. The pp (PbPb) dataset used for this analysis corresponds to an integrated luminosity of 27.4 pb−1 (530 μb−1). The measured D0 meson pT spectrum in pp collisions is well described by perturbative QCD calculations. The nuclear modification factor, comparing D0 meson yields in PbPb and pp collisions, was extracted for both minimum-bias and the 10% most central PbPb interactions. For central events, the D0 meson yield in the PbPb collisions is suppressed by a factor of 5–6 compared to the pp reference in the pT range of 6–10GeV/c. For D0 mesons in the high-pT range of 60–100GeV/c, a significantly smaller suppression is observed. The results are also compared to theoretical calculations.