An STM functions based on the principles of quantum tunneling. When a voltage is applied between the STM tip and the sample, electrons tunnel through the vacuum gap between them. The tunneling current is highly sensitive to the distance between the tip and the sample, enabling the microscope to detect variations at the atomic scale. By scanning the tip across the sample and keeping the current constant, the STM can map the surface topography.