This thesis describes the development of an attitude determination system for spacecraft based only on magnetic field measurements. The need for such system is motivated by the increased demands for inexpensive, lightweight solutions for small spacecraft. These spacecraft demands full attitude determination based on simple, reliable sensors. Meeting these objectives with a single vector magnetometer is difficult and requires temporal fusion of data in order to avoid local observability problems. In order to guaranteed globally nonsingular solutions, quaternions are generally the preferred attitude specifier. This thesis makes four main contributions. The first is the development of a quaternion based Kalman filter, which is linearized using an exponential map of the correction quaternion. The state space is reduced in dimension, and a covariance singularity is avoided. The second contributions is a detailed study of the influence of approximations in the modeling of the system. The quantitative effects of errors in the process and noise statistics are discussed in detail. The third contribution is the introduction of these methods to the attitude determination on-board the Ørsted satellite. Implementation of the Ørsted filter is discussed and the predicted results are presented. Finally the Kalman filter/smoother is applied to magnetometer data from the Freja satellite. Data is processed off-line, which enables us to estimate a high fidelity dynamic model of the spacecraft. Combined with a careful detection of field perturbations, the result is an significant improvement in accuracy when compared to previous results. The results allow researchers to fully utilize the electric field science measurements.