I'm going to simplify stepper motors here to illustrate the simple, central idea: the (inside) rotor of a stepper motor turns by small, discrete amounts (steps) because the (outside) stator applies magnetic impulses that pull and push it around.
The rotor itself is made from two discs, a little like gears, one of which is a magnetic north pole (red) and the other is a south pole (blue). When we put the two discs back to back, we get north and south pole teeth alternating around the edge. If you find that hard to picture, imagine your left hand is a magnetic north pole and is colored red, while your right hand is a magnetic south pole and colored blue. If you put one hand on top of the other so the fingers of one hand alternate with the fingers of the other, then look down, you'll see alternating north and south pole "teeth" (the fingers) around the edge. That's effectively what we have in the rotor of a stepper motor.
Around the edge of the rotor, we have the stator: in this example, four electromagnets that can be switched on and off individually. Generally the electromagnets in a stepper motor work in pairs, with each opposing pair of magnets switching on together to make a north pole at the same time, followed by the magnets at right angles, which also work together. I prefer to draw it a slightly different way, which I think is simpler and easier to understand. Exactly what switches on when depends on how many rotor teeth (steps) there are and how many electromagnet coils surround them: the geometry and alignment of a stepper motor has to be just right to make the rotor turn.
The right electromagnet is energized and becomes a north pole (red) and the left electromagnet becomes a south pole (blue). This pulls the rotor around by one step so a blue tooth on the rotor snaps toward the right electromagnet and a red tooth snaps toward the left electromagnet.
Now the bottom electromagnet becomes a north pole, the top magnet becomes a south pole, and the two horizontal magnets are switched off. Again, the teeth of the rotor are pulled around by one step.
The vertical magnets are now switched off and the horizontal magnets are switched on again, but with the opposite polarity (pattern of magnetism) that they had before. The teeth of the rotor advance by one more step.
Finally, the vertical magnets are switched on again, in the opposite polarity to before, and the horizontal magnets are switched off. The rotor mores around one more step. The whole cycle then repeats.
Remember that a stepper motor isn't really designed to keep spinning around and around: by sending as many or as few impulses to the outer electromagnets as necessary, we can make the rotor turn through a certain number of steps (and, therefore, by a precise angle). We can make it rotate the opposite way by reversing the electric current.