Sensors based on the nitrogen-vacancy defect in diamond are being developed to measure weak magnetic and electric fields at the nanoscale. However, such sensors rely on measurements of a shift in the Lamor frequency of the defect, so an accumulation of quantum phase causes the measurement signal to exhibit a periodic modulation. This means that the measurement time is either restricted to half of one oscillation period, which limits accuracy, or that the magnetic field range must be known in advance. Moreover, the precision increases only slowly (as T -0.5) with measurement time T (ref. 3). Here, we implement a quantum phase estimation algorithm on a single nuclear spin in diamond to combine both high sensitivity and high dynamic range. By achieving a scaling of the precision with time to T -0.85, we improve the sensitivity by a factor of 7.4 for an accessible field range of 16 mT, or, alternatively, we improve the dynamic range by a factor of 130 for a sensitivity of 2.5 μT Hz -1/2. Quantum phase estimation algorithms have also recently been implemented using a single electron spin in a nitrogen-vacancy centre. These methods are applicable to a variety of field detection schemes, and do not require quantum entanglement.