A driver loses control when the vehicle goes in a direction different from the one indicated by the position of the steering wheel. This typically occurs when a driver tries to turn very hard (swerve) or to turn on a slippery road. Then the vehicle may understeer or oversteer.
When a vehicle understeers it turns less than the driver intended and continues in a forward direction because the front wheels have insufficient traction. When it oversteers it turns more than the driver intended because the rear end is spinning or sliding out.
ESC uses sensors in the car (wheel speed sensors, steering wheel position sensors, yaw sensors, etc.) to determine which direction the driver wants the car to go, and compares that to which way the car is actually going. If the system senses that a skid is imminent or has already started -- in other words, that the car is not going in the direction the driver is telling it to go -- it can apply the brakes on individual wheels to bring the car back under control. Because the system can brake individual wheels, whereas the driver can only brake all four wheels at once, ESC can recover from skids that a human driver can't.
If my car has electronic stability control, does that mean I can't lose control of my car??
NO! Even with ESC, it is still possible to lose control of the car.
Excessive speed, slick roads, and excessively worn or improperly inflated tires are all factors that can reduce ESC's effectiveness.