How PageRank Works and How to Implement It in Python

We already know that links from page A to page B pass PageRank, but what about links from page A to page A itself? In this post we'll look at what PageRank is, other algorithms for calculating a page's authority, and how to calculate PageRank in Python. That way we'll find out what happens when a page links to itself.

What is PageRank

PageRank is Google's way of deciding how important a page is. It's considered one of the most important factors in how a page ranks in search results, along with content and RankBrain. This is mentioned at minute 30:20 of this video:

PR is a numerical value that represents how important a page is on the web. When one page links to another, it's basically casting a vote for it.

How PageRank worksPatent US6285999B1 – Method for node ranking in a linked database

That's why the more votes a page gets, the more important it must be, and the more its own votes will be worth.

Google hasn't used the original PageRank formula since 2006

The original PageRank algorithm is no longer the same, and Google hasn't used this formula since 2006, as has been confirmed.

PageRank formulaOriginal PageRank formula

 

Also, according to Google's patents, a page's authority could be calculated in many other ways besides PR. For example, with the Hilltop Algorithm, Hyperlink-Induced Topic Search (HITS), TrustRank, Topic-Sensitive PageRank, the Reasonable Surfer Model, Weighted PageRank, Entity Salience and other algorithms we don't know about. And, as discussed in Mariani, M. S. et al. Ranking nodes in growing networks: When PageRank fails, because PageRank is static (it doesn't take into account how long a link has been around), it sometimes fails to rank the best pages correctly. This is something Google has probably already taken into account, given that people buy expired domains to redirect them. See minute 29:39 of the following video:

What hasn't changed in all this time is that the calculation takes into account the number of outgoing links (whether or not they point to the page itself). You can see this in the variable C in the formula above (it's the denominator inside the summation).

Implementing PageRank in Python

To calculate PageRank, we'll rely on a Python implementation of the PageRank algorithm. We'll use the Fast PageRank library, which I've set up ready to run in Google Colab (you can access the notebook here).

Let's do the following exercise to see how PageRank flows in different cases. We'll use a damping factor (d in the equation above) of 85%, which Google applies so that PageRank doesn't tend to infinity.

1. One page links to another

PageRank: one page links to another

  • PR A = 0.35
  • PR B = 0.65

2. Pages that link to each other

PageRank: pages that link to each other

  • PR A = 0.5
  • PR B = 0.5

3. A page that links to two others

PageRank: a page that links to two others

  • PR A = 0.26
  • PR B = 0.37
  • PR C = 0.37

4. A page that links to another page and to itself

We finally get to the reason for this post:

PageRank: a page that links to another page and to itself

  • PR A = 0.5
  • PR B = 0.5

So yes, linking to itself does pass PR. Compare this with the first graph to see how much the self-link adds to page A.

5. A page that links to two others and to itself

PageRank: a page that links to two others and to itself

  • PR A = 0.33
  • PR B = 0.33
  • PR C = 0.33

Now let's add an internal link from a page D to A:

PageRank nodes

  • PR A = 0.36
  • PR B = 0.24
  • PR C = 0.24
  • PR D = 0.14

Thanks to A's link to itself, page A gains even more strength. If we removed that self-referencing link, we'd get:

  • PR A = 0.28
  • PR B = 0.27
  • PR C = 0.27
  • PR D = 0.15

And now let's have B and C link back to A:

PageRank graph

  • PR A = 0.56
  • PR B = 0.19
  • PR C = 0.19
  • PR D = 0.03

Conclusion

We've seen that, according to the original PageRank formula, self-referencing links pass weight, or "link juice".

This could make sense depending on how you want to boost the pages on your site (PageRank sculpting).

Natzir Turrado 08 September 2011

Share

Facebook Linkedin Twitter

More articles

CTR Affects SEO, but Why Can't It Be Artificially Manipulated?

Lately there's been a lot of noise about CTR and its impact on SEO: some say manipulating CTR works, others that it seems to work, and others that it simply doesn't work… For newcomers: in SEO, CTR (click-through rate) is a ratio that measures how effective a result is on Google's search results page (SERP). […]

Read more

It's Not GEO or AEO, It's Just SEO: How to Do SEO for AI

Every time a new concept or acronym pops up in the digital marketing world (GEO, AEO, LLMO, GAIO, LSO, LEO, etc.), the debate is whether we're looking at a real revolution or the same old strategy under a new name. In my experience, optimizing for large language models (LLMs) is, at its core, the logical […]

Read more