← All articles
technologyhow do search engines workweb crawlingsearch rankingAugust 17, 20269 min read

How Do Search Engines Work? Crawling, Indexing, and Ranking Explained

By the BrainSnail editorial team. How these articles are written and checked, and how to tell us when one is wrong.

Search engines discover web pages, process and store information about them, then rank possible results when you type a query. The details are complex, but the basic path can be understood as crawling, indexing, and ranking.

Crawling: discovering pages

Search engines use automated programs often called crawlers, spiders, or bots to visit pages on the web. A crawler can follow links from one page to another, revisit known pages to look for changes, and discover new URLs from several sources. Site owners can also provide structured files such as sitemaps to help search systems find important pages.

Crawling does not mean every discovered page will appear in search results. A search engine has to decide what it can access, how often to revisit it, and whether the content is suitable for its index. Technical instructions, duplicate pages, inaccessible content, or low-value pages can affect what happens next. This discovery stage is the first part of how search engines work.

The web is far too large to download from scratch every time someone searches. Crawling happens ahead of the user's query, building a continually updated picture of public web content. That is why a brand-new or recently changed page may take some time to be discovered and processed.

Indexing organises information for fast retrieval

After a page is crawled, the search engine analyses its content and structure. It may identify words, topics, headings, links, images, language, and other signals. It then stores useful information in an index, which works more like a giant organised lookup system than a simple folder containing copies of every page.

Indexing is central to how search engines work quickly. When you search for a phrase, the system does not normally scan the live web one page at a time. It consults its prepared index to find pages that might match your intent. This makes it possible to return results in a fraction of a second even for broad queries.

Ranking tries to put useful results first

Once candidate pages are found, ranking systems estimate which ones best answer the query. Search engines can consider many signals, including how closely content matches the words and meaning of the search, the quality and usefulness of the page, links, freshness where it matters, location for local searches, and whether the page is usable on the searcher's device.

When studying how search engines work, avoid imagining one permanent score that decides every result. Different queries need different things. A search for today's weather values freshness and location. A search for a historical definition may reward a stable, authoritative explanation. Ranking systems therefore combine signals differently depending on the request.

Search results can also include formats beyond ordinary blue links, such as images, maps, videos, direct answers, or news. These features still depend on understanding the query and retrieving suitable information. The exact algorithms are proprietary and change over time, but crawling, indexing, and ranking remain a useful high-level model.

Inside the index and the idea of links as votes

The core structure behind fast search is called an inverted index. Instead of storing a list of words for each page, it stores a list of pages for each word. Imagine three short pages: page one says snails are slow, page two says snails eat leaves, and page three says leaves are green. The index entry for snails points to pages one and two, and the entry for leaves points to pages two and three. A search for snails leaves can combine those lists and find page two immediately, without reading anything else.

Links became one of the most famous ranking signals. In the late 1990s, Larry Page and Sergey Brin, then students at Stanford, described an approach called PageRank that treated a link from one page to another as a kind of vote. Votes from pages that were themselves widely linked counted for more. The idea helped their search engine, Google, rank results more usefully than systems relying mainly on matching words. It also encouraged people to create fake links, which is one reason modern ranking uses many signals together.

What happens to your query in a fraction of a second

Before any results are found, the search engine works on the query itself. It may correct a likely spelling mistake, recognise that run, running and ran are forms of the same word, and match synonyms, so a search for cheap flights can also find pages about low-cost airfares. It tries to work out the intent, too: a query containing near me needs local results, while a person's name alone might mean they want news, a biography or a social media profile. This interpretation shapes which parts of the index are searched.

The index itself is far too large for one computer. It is split into many pieces, often called shards, spread across thousands of machines in data centres. Your query is sent to many of them at once, each searches its own piece in parallel, and the best candidates are passed upwards and merged into a single ranked list. Copies of each shard allow the system to keep working if machines fail. Very common queries can also be answered from a cache of recent results, which is part of how a search over billions of pages can return answers so quickly.

Why rare words count for more

Before links or quality signals come into play, a search engine needs some measure of how well a page's words match the query, and a classic answer is called TF-IDF. TF, or term frequency, counts how often a query word appears on a page. IDF, or inverse document frequency, measures how rare the word is across the whole collection. Imagine an index of one million pages and the query the axolotl. The word the appears on perhaps 900,000 pages, so finding it tells you almost nothing. Axolotl might appear on only 1,000 pages, so a page containing it is far more likely to be relevant.

A common formula takes the base-10 logarithm of the total number of pages divided by the number containing the word. For the, that is the logarithm of 1,000,000 divided by 900,000, about 0.05. For axolotl, it is the logarithm of 1,000,000 divided by 1,000, which is 3, so the rare word counts more than sixty times as much. Refinements stop a page winning simply by repeating a word, since each extra mention adds less than the one before. Modern engines go further, using models that compare meanings rather than exact words, but the old insight that rare words carry more information still applies.

Robots.txt and keeping pages out of results

Site owners can give instructions to crawlers through a plain text file called robots.txt, placed at the root of a website. It lists rules such as Disallow: /drafts/, asking particular crawlers, or all of them, not to fetch certain paths. The convention dates from 1994, when the engineer Martijn Koster proposed it after early crawlers had overloaded some servers, and it was finally published as a formal internet standard in 2022. Crucially, it is a request rather than a lock. Well behaved crawlers obey it, but nothing forces other software to, so it must never be used to protect private information.

A common mistake is to assume that blocking a page in robots.txt keeps it out of search results. It only stops the page being fetched. If other sites link to the address, a search engine may still list the bare URL with little or no description, because it knows the page exists without having read it. The reliable way to keep a page out of the index is a noindex instruction, placed in the page's HTML or sent with its headers. Ironically, this only works if crawling is allowed, since a crawler that never fetches the page never sees the instruction telling it to stay out.

The takeaway

Crawlers discover pages, indexing systems organise what those pages contain, and ranking systems select and order results for each query. Search is fast because much of the web has been processed in advance. The best result is not simply the page that repeats a keyword most often, but the page the system estimates will be most useful.

Practise this

Questions from The Web and How It's Built

Reading about something is not the same as being able to recall it. These are real questions from the The Web and How It's Built unit in our Technology track, answers and explanations included. The unit has 119 in total across 23 steps.

  • Type the answerLevel 2

    1. Which three-letter language is used to style web pages, controlling colors, fonts, and layout?

    Answer: CSS

    CSS is the styling language that decides how a web page looks.

  • Type the answerLevel 1

    2. What four-letter name is given to the language used to build the structure of a web page?

    Answer: HTML

    HTML is the markup language that structures the content of a web page.

  • Fill the blankLevel 2

    3. JavaScript makes a page ____, so it can react when you click or type.

    • interactivecorrect
    • colorful
    • heavier
    • printed

    Interactive means the page can respond to the user, which is JavaScript's main job.