In this post, I will explain how stepper motors works. Stepper motors are motors which spin on steps due to activation of coils in the stator. This type of motor has many input wires to turn on a specific coil.
The stator teeth have coils and the rotor have many teeth, the motor spin depending the sequence the coils are turned on. I will use this model below to explain better.
The stator has 8 coils, so you have 4 signals sources (A, B, C and D). If you turn on only the coils A and -A, the teeth 1 and 4 will be aligned, turn off coils A and -A and turn on the coils B and -B, the teeth 6 and 3 will align and the motor will turn 45ᵒ, turn on the coils D and -D and the closer teeth will be aligned with these coils. In this model, the number of rotor teeth is 2 less than the teeth in the stator, so only one axis in the rotor is aligned with the coils.
You can have more precision with this method, if you turn on two adjacent coils like -A and D and A and -D the rotor will be aligned between these coils, turn off one of the pair and the rotor will move in 22.5ᵒ.
Practical stepper motor
This is the interior of a commonly used stepper motor, the rotor has a permanent magnet inside and a great number of teeth, the principle is the same explained before but now two pair of coils with 90ᵒ of distance must be turned to make a step angle, turn off the two pairs and turn on another two pairs and the rotor will do another step angle. The permanent magnet create an attraction force in one side and a repulsion force in other side to help in the step angle.