As more and more gas enters a fuel tank, the distance between the liquid and the nozzle shrinks, and a small pipe next to the gas nozzle sinks into the rising fuel. At that point, the small pipe's air pressure is choked off, stopping the flow of gasoline.
This small pipe is called a venturi, but its operation is not foolproof. In some cases, the shutoff valve kicks into action before the tank is full, as some of the flowing gasoline backs up on its journey into the fuel tank. The result is that the gas handle jumps open before the pumping is done. The consumer presses the handle again, running the risk of gas overflowing and running down the side of the car. The best tactic is to pause for a short time and then press the handle as this gives the fuel time to stabilize level in the tank.
The purpose of this fuel shutoff valve is to minimize the danger of pumping gas as well as the risk to the environment. If the tank runs over, spilling gas onto the ground, a fire hazard results. The gasoline also causes environmental damage whether it drains into a sewer system or runs into nearby grass.