Motors turn electricity into motion and generators turn motion into electricity. Both machines use the same parts: brushes, magnets and wires. They are similar machines working in different directions.
In a motor, electricity flows through coiled wires to create a magnetic field. The push and pull of the magnetic field against magnets in the motor creates motion. That motion can be used to turn an axle.