Of the potential volatile sources for the terrestrial planets, the CI and CM carbonaceous chondrites are closest to the planets' bulk H and N isotopic compositions. For the Earth, the addition of approximately 2-4 wt% of CI/CM material to a volatile-depleted proto-Earth can explain the abundances of many of the most volatile elements, although some solar-like material is also required. Two dynamical models of terrestrial planet formation predict that the carbonaceous chondrites formed either in the asteroid belt (`classical' model) or in the outer Solar System (5-15 AU in the Grand Tack model). To test these models, at present the H isotopes of water are the most promising indicators of formation location because they should have become increasingly D-rich with distance from the Sun. The estimated initial H isotopic compositions of water accreted by the CI, CM, CR and Tagish Lake carbonaceous chondrites were much more D-poor than measured outer Solar System objects. A similar pattern is seen for N isotopes. The D-poor compositions reflect incomplete re-equilibration with H2 in the inner Solar System, which is also consistent with the O isotopes of chondritic water. On balance, it seems that the carbonaceous chondrites and their water did not form very far out in the disc, almost certainly not beyond the orbit of Saturn when its moons formed (approx. 3-7 AU in the Grand Tack model) and possibly close to where they are found today.This article is part of the themed issue 'The origin, history and role of water in the evolution of the inner Solar System'.