  We analyze magnetometry using an optically levitated nanodiamond. We consider
a configuration where a magnetic field gradient couples the mechanical
oscillation of the diamond with its spin degree of freedom provided by a
Nitrogen vacancy center. First, we investigate measurement of the position
spectrum of the mechanical oscillator. We find that conditions of ultrahigh
vacuum and feedback cooling allow a magnetic field gradient sensitivity of 1
$\mu$Tm$^{-1}$/$\sqrt{\mbox{Hz}}$. At high pressure and room temperature, this
sensitivity degrades and can attain a value of the order of 100
$m$Tm$^{-1}$/$\sqrt{\mbox{Hz}}$. Subsequently, we characterize the magnetic
field gradient sensitivity obtainable by maneuvering the spin degrees of
freedom using Ramsey interferometry. We find that this technique can offer
photon-shot noise and spin-projection noise limited magnetic field gradient
sensitivity of 100 $\mu$Tm$^{-1}$/$\sqrt{\mbox{Hz}}$. We conclude that this
hybrid levitated nanomechanical magnetometer provides a favorable and versatile
platform for sensing applications.
