The process that a search engine uses to determine where pages will rank is called an algorithm. You'll hear a lot about search engine algorithms as you continue to read more about this topic on the web. The reason is that all other elements of a search engines are relatively basic and remain largely unchanged over time when compared to the complexity and dynamism of their algorithm.
A simplified analogy of a search engine algorithm is that of the sliders on a stereo equalizer. Sliding each slider up or down has an effect on the end result (the sound). Search engines can similarly control how much weight a particular variable carries adding to a variables importance or decreasing it as they deem necessary. Based on this information, the search engine can build up an index where it can pull up a list of the best entries for any term you search for.
As time goes by, people learn to understand some components of the search engine algorithm and can manipulate their way to the top rank without being a page of value to the search engine users. In order to prevent this, search engines strive to find new factors that help them measure quality and/or will alter and adjust the weight or their variables on a regular basis.