The time-of-flight of light pulses has long been used as a direct measure of distance(1,2), but state-of-the-art measurement precision using conventional light pulses or microwaves peaks at only several hundreds of micrometres(3,4). Here, we improve the time-of-flight precision to the nanometre regime by timing femtosecond pulses through phase-locking control of the pulse repetition rate using the optical cross-correlation technique(5,6). Our experiment shows an Allan deviation of 117 nm in measuring a 0.7-km distance in air at a sampling rate of 5 ms once the pulse repetition is phase-locked, which reduces to 7 nm as the averaging time increases to 1 s. This enhanced capability is maintained at long range without periodic ambiguity, and is well suited to lidar applications such as geodetic surveying(7), range finders(8) and absolute altimeters(9). This method could also be applied to future space missions involving formation-flying satellites for synthetic aperture imaging(10,11) and remote experiments related to general relativity theory(12).