One way to do this is to briefly stop driving the motor, long enough to let any residual current from the driving voltage die down, and then simply measure the voltage. The time it takes the current to settle will depend on the inductance of the windings. This is simple to understand, and the undriven interval can be made quite short, but this has obvious disadvantages.
Another method involves a clever use of Ohm's law. A motor can be modeled as a series circuit of an inductor, a resistor, and a voltage source. The inductor represents the inductance of the motor's windings. The resistor is the resistance of that wire. The voltage source represents the back-EMF, and it is directly proportional to the speed of the motor.

If we can know the resistance of the motor, and we can measure the current in the motor, we can infer what the back-EMF must be while the motor is being driven! Here's how:
We can ignore \$L_m\$ so long as the current through the motor is not changing much, because the voltage across an inductor proportional to the rate of change of current. No change in current means no voltage across the inductor.
If we are driving the motor with PWM, then the inductor serves to keep the current in the motor relatively constant. All we care about then, is really the average voltage of \$V_{drv}\$, which is just the supply voltage multiplied by the duty cycle.
So, we have an effective voltage we are applying to the motor, which we are modeling as a resistor and a voltage source in series. We also know the current in the motor, and the current in the resistor of our model must be the same because it is a series circuit. We can use Ohm's law to calculate what the voltage across this resistor must be, and the difference between the voltage drop over the resistor and our applied voltage must be the back-EMF.
Example:
motor winding resistance \$ = R_m = 1.5\:\Omega\$
measured motor current \$= I = 2\:\mathrm A \$
supply voltage \$= V_{cc} = 24\:\mathrm V \$
duty cycle \$ = d = 80\% \$
Calculation:
24V at an 80% duty cycle is effectively applying 19.2V to the motor:
$$ \overline{V_{drv}} = dV_{cc} = 80\% \cdot 24\:\mathrm V = 19.2\:\mathrm V $$
The voltage drop over the winding resistance is found by Ohm's law, the product of the current and winding resistance:
$$ V_{R_m} = IR_m = 2\:\mathrm A \cdot 1.5\:\Omega = 3\:\mathrm V $$
The back-EMF is the effective driving voltage, less voltage across the winding resistance:
$$ V_m = \overline{V_{drv}} - V_{R_m} = 19.2\:\mathrm V - 3\:\mathrm V = 16.2\:\mathrm V $$
Putting it all together into one equation:
$$ V_m = dV_{cc} - R_m I $$
Best Answer
Inductive components like motor winding resist sudden changes in current. That's because the magnetic field caused by the current needs time to build up or decrease. That means that when current is flowing and this is suddenly cut off, the winding will try to maintain that current, and becomes a power source generating a voltage to be able to do so. It gets its power from the built up magnetic field.
Since the winding is now a power source instead of a consumer the voltage is reversed for the same current flow direction. That also explains how the voltage on a coil can become higher than the power supply: instead of subtracting the voltage over it you add it to the power supply. That's why you need a flyback diode on for instance a relay coil: the diode will allow the back emf to flow back to the power supply without damaging the switching transistor.