A motor is an electrical machine which converts electrical energy into mechanical energy. The principle of working of a DC motor is that "whenever a current carrying conductor is placed in a magnetic field, it experiences a mechanical force". The direction of this force is given by Fleming's left hand rule and it's magnitude is given by F = BIL. Where, B = magnetic flux density, I = current and L = length of the conductor within the magnetic field.
Fleming's left hand rule: If we stretch the first finger, second finger and thumb of our left hand to be perpendicular to each other AND direction of magnetic field is represented by the first finger, direction of the current is represented by second finger then the thumb represents the direction of the force experienced by the current carrying conductor.
working principle of a DC motor. When armature windings are connected to a DC supply, current sets up in the winding. Magnetic field may be provided by field winding (electromagnetism) or by using permanent magnets. In this case, current carrying armature conductors experience force due to the magnetic field, according to the principle stated above.
Commutator is made segmented to achieve unidirectional torque. Otherwise, the direction of force would have reversed every time when the direction of movement of conductor is reversed the magnetic field.
This is how a DC motor works!