The Math Behind Google's PageRank Algorithm

Before Google could rank the web, it had to answer a strange question: how important is a page, if importance is defined by other pages you'd also have to rank? Here's how a random surfer and a bit of linear algebra solve it.

By Petrus Sheya

August 4, 2026 · 6 min read

Type a question into Google and it picks the best answer out of billions of pages, in a fraction of a second, without reading a single one of them for meaning. In 1998, two Stanford students, Larry Page and Sergey Brin, needed a way to rank pages using nothing but the links between them.

Here's the puzzle they ran into. A page is important if important pages link to it. But you don't know which pages are important until you've ranked them. The definition needs its own answer as an input.

That circular problem has a genuinely elegant solution, and it doesn't require reading a single word of content. Let's build it from scratch.


Forget search for a second. Think of the web as a giant city of pages, and every link from page A to page B as A saying "I trust B enough to send you there."

Count the votes and you get a rough popularity score: pages with more incoming links are probably more useful. That's a start, but it breaks immediately. A link from a random abandoned blog and a link from a major news outlet count as the same single vote. That's clearly wrong.

So the fix seems obvious: weight each vote by the importance of the page casting it. A link from an important page should count for more.

...and there's the circular problem again. To weight a vote by importance, you need to already know the importance.


Escaping the circle: imagine a bored surfer

Here's the trick. Instead of trying to define importance directly, simulate it.

Picture someone with infinite patience, sitting at a random page, clicking a random link on that page, landing on a new page, clicking again, forever. No goal, no search intent. Just clicking.

Some pages get visited constantly, because lots of other pages link into them. Some barely get visited at all. A page's importance is just how often the surfer ends up there.

The surfer picks a random outgoing link every hop. Watch which page it keeps landing on, that's popularity emerging from pure randomness.

A1B0C0D0E0
Hops taken0
Most visitedA (100%)

Press play and watch the visit counts next to each page. Notice they don't grow evenly. One page pulls ahead early and stays ahead, not because it's special, but because more arrows point into it. That's the whole idea. No content was read. No votes were manually weighted. Importance just fell out of where the surfer naturally piles up.

This is the intuition. Now let's turn it into something we can actually compute, without literally running a random walk for a trillion steps.


Writing the vote mathematically

If importance is "where the surfer tends to be," then a page's rank should equal the sum of the rank it receives from every page linking to it.

But here's the catch we saw in the last section: a page with 10 outgoing links can't give its full vote to all 10. It splits its vote evenly across however many links it has. A hub with 5 outgoing links gives each one only a fifth of its rank.

The hub always has the same importance, 0.30. Slide its out-degree up and watch each individual vote get diluted.

0.30PHrank = 0.30
Vote received by P0.300

Slide the hub's out-degree up. The hub's own importance never changes, 0.30, fixed. But watch the number arriving at page P shrink every time the hub adds one more outgoing link. A vote is worth rank divided by how many places that rank has to go.

We write this as:

r(P)=QPr(Q)L(Q)r(P) = \sum_{Q \to P} \frac{r(Q)}{L(Q)}

where the sum runs over every page QQ that links to PP, and L(Q)L(Q) is the number of outgoing links on QQ. That's the entire idea, in one line: your rank is the sum of everyone else's rank, diluted by how many ways they spread it.


Solving the circle with repetition

That formula still has r(Q)r(Q) on the right side depending on ranks we haven't found yet. Here's how you get around needing them upfront: guess, then correct the guess, over and over.

Start every page tied, at 1/N1/N for NN total pages. Apply the formula once. The ranks shift a little. Apply it again. They shift less. Keep going, and the ranks stop moving. That fixed point, the one where applying the formula again changes nothing, is the answer.

Every page starts tied. Slide k forward and watch the ranks settle, past a certain point another round barely changes anything.

0.200A0.200B0.200C0.200D0.200E
Leading pageA
Change since k-10.0000

Drag kk up from zero. The bars jump around at first, then settle into place, and by the time you're a dozen iterations in, another round barely nudges anything. Watch the "change since k-1" number in the corner: it's heading straight for zero. That's convergence, and it's the actual algorithm Google runs, called power iteration.

This works because the update is really a matrix multiplication, applied to the rank vector again and again. Do that enough times and any starting guess gets pulled toward the same answer, the dominant eigenvector of the link matrix. You don't need to know eigenvector theory to use this, the iteration alone gets you there.


The trap that breaks the random walk

There's a problem hiding in this setup. What happens if a group of pages link to each other in a closed loop, and nothing inside that loop links back out?

The surfer wanders in... and never leaves. Every click keeps them inside the loop. Given enough time, all of the rank in the entire system drains into that trap, and every page outside it converges to zero. Mathematicians call this a rank sink.

T has no way out, just a link back to itself. At d = 1 every bit of rank that wanders in gets stuck there forever.

A0%B0%T100%
Rank trapped in T100.0%

Node T only links to itself. At d=1d = 1, watch the "rank trapped in T" number climb toward 100%, the rest of the graph gets starved. Now drag dd down. T's stranglehold loosens, and rank flows back to A and B.

What's dd doing? At every step, with probability 1d1 - d, the surfer gets bored of clicking links entirely and teleports to a completely random page instead of following an outgoing link. It's a small chance of a random reset, applied at every single step. That reset is enough to pull the surfer back out of any trap they wander into.


The actual formula Google uses

Put the teleport into the update rule and you get the real PageRank equation:

r(P)=1dN+dQPr(Q)L(Q)r(P) = \frac{1-d}{N} + d \sum_{Q \to P} \frac{r(Q)}{L(Q)}

The first term spreads a small guaranteed amount of rank to every page, evenly, no matter what the link structure looks like. The second term is the vote-counting we already built. Brin and Page picked d=0.85d = 0.85 in the original paper: 85% of the time, follow a link, 15% of the time, teleport somewhere random.

That one constant is the difference between a formula that can collapse into a trap and one that always converges to a stable, meaningful answer, for any web, no matter how it's linked.


The short version

PageRank never reads a single word of a page. It only looks at who links to whom, and it solves the "importance depends on importance" problem by simulating a random surfer and asking where they spend their time. The math for that turns out to be a sum of incoming votes, each one divided by how many links its source page has. Repeating that update enough times converges to a stable answer, and adding a small random teleport chance keeps the whole system from collapsing into a dead-end loop.

Twenty-five years later, the web looks nothing like it did in 1998. But the core idea, importance as where a random walk settles, still sits underneath ranking systems far beyond search engines.


All visualizations are interactive React components running entirely in your browser. The random surfer uses requestAnimationFrame for its hop timing, and the power iteration and damping demos compute exact PageRank values live from the underlying graphs. No libraries beyond React.