This paper presents methods to calibrate and compensate for non-zero biases, non-unit scale factors, axis misalignments and cross-axis sensitivities of both the tri-axial accelerometer and gyroscopic setups in a micro-electro-mechanical systems (MEMS) based inertial measurement unit (IMU). These methods depend on the Earth's gravity as a stable physical calibration standard. Specifically, the calibration of gyroscopes is significantly improved by comparing the outputs of the accelerometer and the IMU orientation integration algorithm, after arbitrary motions. The derived property and proposed cost function allow the gyroscopes to be calibrated without external equipment, such as a turntable, or requiring precise maneuvers. Both factors allow the IMU to be easily calibrated by the user in the field so that it can function as an accurate orientation sensor. A custom-made prototype IMU is used to demonstrate the effectiveness of the proposed methods, with data that are carefully obtained using prescribed motions, as well as those less rigorously collected from the IMU when it is mounted on the head of a user or held in hands with brief random movements. With calibration, the observed average static angular error is less than a quarter of a degree and the dynamic angular error is reduced by a factor of 2 to 5.