This is what happen after you type keywords on Google search and click enter. This complex process is all done in less than a second, 300 million times a day, generating over $20 billion a year for Google!
From official word:
The software behind our search technology conducts a series of simultaneous calculations requiring only a fraction of a second. Traditional search engines rely heavily on how often a word appears on a web page. We use more than 200 signals, including out patented PageRank algorithm, to examine the entire link structure of the web and determine which pages are most important. We then conduct hypertext-matching analysis to the specific search being conducted. By combining overall importance and query-specific relevance, we’re able to put the most relevant and reliable results first.
Infographic by PPC Blog