We present 3-axis stabilized spacecraft attitude determination algorithm using the magnetometer. The magnetometer has been used as a reliable, light-weight and inexpensive sensor in attitude determination and reaction wheel momentum dumping system. Recent studies have attempted to use the magnetometer when other attitude sensor, such as star tracker, fails. The differences between the measured and computed the Earth's magnetic field components are spacecraft attitude errors. In this paper, we propose extended Kalman filter(EKF) to determine spacecraft attitude with the magnetometer data and gyro-measured body rates. We develop and simulate this algorithm using MATLAB/SIMULINK. This algorithm can be used as a backup attitude determination system.