STM operates by moving a sharp tip very close to the surface to be imaged. When a voltage is applied, electrons tunnel between the tip and the surface, creating a current. This tunneling current is highly sensitive to the distance between the tip and the surface, allowing the microscope to produce atomic-scale images.