The water after falling on the surface of Earth through precipitation (typically rain) then permeates through the top soil layer and and filters down to the sub-surface. This movement may not always be vertical; it may be a combination of horizontal and vertical motion. It depends on a number of factors, such as soil porosity and ground slope.
The purification of water takes place through a number of processes, including filtration, metabolism of organic matter by soil microorganisms, adsorption onto soil particles, and predation of microbes by higher order microorganisms. The filtration itself occurs through a number of processes, the most common of which is physical straining. In simpler terms, there is a definite gap between adjacent soil particles, called pore space. Any particle or contaminant bigger than this inter-particle spacing will get stuck and hence removed from the infiltrating water. The attached image shows the particle straining through subsurface soil.