This paper describes an unscented Kalman filter approach to estimate the bias in magnetic field measurements. A microelectromechanical systems attitude heading reference system (MEMS AHRS) was used to measure the magnetic field, together with the acceleration and angular rate. A magnetic field is usually used for yaw detection, while the acceleration serves to detect the roll and pitch. Magnetic field measurements are vulnerable to distortion due to hard-iron effect and soft-iron effect. The bias in the measurement accounts for the hard-iron effect, and this paper focuses on an approach to estimate this bias. The proposed method is compared with other methods through experiments that implement the navigation of an underwater robot using an AHRS and Doppler velocity log. The results verify that the compensation of the bias by the proposed method improves the navigation performance more than or comparable to the compensation by other methods.