A measurement of J/ ψ and ψ(2 S) production is presented. It is based on a data sample from Pb+Pb collisions at sNN=5.02TeV and pp collisions at s=5.02TeV recorded by the ATLAS detector at the LHC in 2015, corresponding to an integrated luminosity of 0.42nb-1 and 25pb-1 in Pb+Pb and pp, respectively. The measurements of per-event yields, nuclear modification factors, and non-prompt fractions are performed in the dimuon decay channel for 9<40 GeV in dimuon transverse momentum, and - 2 < yμμ< 2 in rapidity. Strong suppression is found in Pb+Pb collisions for both prompt and non-prompt J/ ψ, increasing with event centrality. The suppression of prompt ψ(2 S) is observed to be stronger than that of J/ ψ, while the suppression of non-prompt ψ(2 S) is equal to that of the non-prompt J/ ψ within uncertainties, consistent with the expectation that both arise from b-quarks propagating through the medium. Despite prompt and non-prompt J/ ψ arising from different mechanisms, the dependence of their nuclear modification factors on centrality is found to be quite similar.