How Facebook’s algorithm works & how it knows what you want

Povilas KrikščiūnasPovilas Krikščiūnas

To understand how Facebook is able to accurately predict what you will find interesting, let’s look into what information Facebook is able to gather on you.

Facebook declares that their main mission is “to connect people with stories that matter to them the most”. Considering that Facebook’s whole business model is based on supplying users with relevant content and ads, their mission statement is not too far off the truth.

How content ends up in your feed

Facebook has developed an algorithm called RANKING which predicts what content each user will be interested in the most.

The basic principle behind RANKING is quite straight-forward. There are 4 steps that the algorithm follows, before it decides what content should pop up in a user’s personalised feed. Here’s how it can be broken down:

Step 1. Gathering all available content the user is connected to

The algorithm gathers all content which is available on Facebook and that a user has a connection to (from friends, pages they follow themselves, posts your friends have liked or commented on, etc.).

Step 2. Universal Signals

Universal signals determine the quality of the content. 

The number of views, likes, comments on the post, and even the reputation of the page or profile itself are taken into account.

All content, including images, is scanned with AI. For example, once you upload an image on Facebook, its AI will scan what is portrayed inside it: how many people, what do they look like, what objects are in the photo, etc. (source:

This can help ensure that a user’s feed has a variety of different content and does not end up containing only selfies with a bunch of likes from fake accounts.

A funny trend that content creators have spotted is that posts which contain URL links will rank poorly and have less organic reach, because Facebook does not want for people to be taken off its platform (LinkedIn is also suspected to be guilty of this trick).

Step 3. Real-Time Signals

Real-time signals evaluate the recency and location proximity of the content.

For example, new posts will get an initial boost in the rankings before they start to fade away. Or, content that suddenly blows up in engagement in a certain region may indicate local breaking news stories.

Step 4. Personal Signals

Tracking and determining personal signals is where things start to get really interesting. 

Officially, ‘Personal Signals’ determine “how close people are to the person or Page that has shared a post and is determined by signals like how many times someone has interacted with the poster”.

But while the official description mentions only a straight-forward example of reconnecting the user with someone they have already interacted with in the past, the truth is that ‘Personal Signals’ generate predictions on what new content the user will be interested in, including ads.

In order to make accurate predictions, absolutely all and any history that Facebook has attached to your profile will be used.

Your Facebook profile

Let’s start with the obvious – your profile history is a goldmine for advertisers. It has been gathering data since the day you opened your account.

Unlike Google, Facebook allows advertisers to display ads to a visitor only if their device is logged into a Facebook profile.

Therefore, all Facebook ads are personalized.

What history does Facebook have on you exactly? Let’s go through some very common information used by advertisers.

What you’ve filled in yourself

From demographic information to your education, you’ve told Facebook quite a lot about yourself. But before you start panicking and deleting your Facebook profile, I can tell you that this data is actually not that interesting.

Sure, there are some big brands that launch global ‘branding campaigns’ targeting a certain demographic. However, in the digital marketing world it’s considered quite lame to target someone solely based on their demographics. Because there is so much more data available.

We don’t want to know what your gender is, we want to know what you’re interested in.

Tracking what you do inside Facebook

Every time you engage with content inside Facebook or one of its products (i.e. Instagram), that information will get attached to your Facebook profile.

Because Facebook tags every single piece of content, it is able to determine your interests through the content you interact with.

  • What was that video you just watched about?
  • What article did you just click on?
  • Did you just press “See More” on a post about dietary supplements?
  • Did your thumb stop scrolling when you saw an image of a pair of awesome sneakers?

It’s all being recorded and used to predict what content you’re going to be interested in next.

In fact, you can check out all of the Interests Facebook has attached to your profile in your account settings:

Here’s an example of some interests attached to my Facebook profile:

While most of them make sense, some interests on your profile may surprise you. 

For example, you can see that one of the interests attached to my profile is ‘Eurovision Song Contest 2016’, which at the time of writing this article has happened more than 3.5 years ago.

Also, you may see some interests that you won’t even have any idea how they got there. For example, one of the interests attached to my profile is ‘San Diego Zoo’. I have never been to San Diego in my life, and seeing how I live in Europe, 9,500 km away, I’m not planning to visit that zoo any time soon.

Overall, your profile history will give Facebook a pretty decent depiction of what content you may find interesting.

However, if Facebook only used information on what content you interact with inside its platform, it would not be anywhere near as efficient at predicting what content you will find interesting next.

That’s not where the goldmine is.

There is another way Facebook is able to gather information on you and attach it to your profile. Let’s talk about it next.

Tracking what you do outside of Facebook

Facebook may be the biggest social media network in the world, but it would be nowhere near as accurate at detecting your interests if it only relied on activity inside its platforms.

For example, if RANKING could only rely on your interests inside Instagram, it would most likely reflect the content that is popular on Instagram anyway.

Luckily, Facebook has a powerful source of information which detects your browsing activity across the whole web and matches it back to your Facebook profile.

It is called the Facebook pixel.

How does the Facebook pixel work

The Facebook pixel is simply a small line of code placed in websites which performs two main activities:

  1. It scans the website and identifies what content is being explored and engaged with.
  2. It connects the website visitor with their Facebook user profile in order to attach this browsing history to their profile.

Let’s take a look at how this looks in real life. Here is an example from BusinessInsider’s website:

Facebook pixel data inside an article on Business Insider
Facebook pixel data inside an article on Business Insider

As you can see in the image, the Facebook pixel scans the website URL, detects the headline, and the main content on the page. In this instance, it even detected that the article is classified as “content_tier: free”.

It will also try to pump in any other additional data it can, for example, scanning the text on each button that I press. Here’s what happened when I clicked the “Subscribe” button:

Facebook pixel automatically scanning data
Facebook pixel automatically scanning data

So, simply by visiting this page, I have already let Facebook know that I am a BusinessInsider reader. Also, the content on the page lets Facebook know what content I may find relevant. 

In this instance, perhaps I am currently more likely to engage with political news related to the US and not the EU, even though my geographical location is in Europe.

This will already put me in a certain category of interests and target audiences. 

For example, I may soon start seeing ads for BusinessInsider’s paid subscription, and the ads may feature news on US politics.

Now, all Facebook has to do is detect whether my website browser is logged into a Facebook account and connect the information to my Facebook profile. This can be simply done by checking my browser cookies and attaching my Facebook account’s userID to the rest of the information detected by the Facebook pixel.

Here is an example of my Facebook userID being matched in my browser’s cookies:

Facebook pixel sending data on my Facebook user ID from and connecting it to
Facebook pixel sending data for the visitor’s Facebook user ID from and connecting it to

In essence, by placing the Facebook pixel on their website, BusinessInsider just became an extension of the Facebook network. It’s as if I had never left the platform in the first place.

The next question you may be asking is: why on Earth would businesses give away their information?

Why businesses give away information to Facebook

So, why would businesses willingly hand over their information to Facebook?

The answer is obvious, it’s because they themselves run Facebook ads.

For one, by placing the Facebook pixel on their website, businesses are able to run remarketing campaigns to show ads to the same people who have already visited their website. 

Businesses trade data for better advertising capabilities
Businesses trade data for better advertising capabilities

But remarketing is only a small portion of what actually happens overall.

By using the Facebook pixel, we connect our website to the whole ad network. Facebook has a lot of data and through the power of machine learning it can find our target audience better than we ever could ourselves.

Machine learning & ad targeting

Remember looking at those interests attached to my profile? Some of them were irrelevant, some of them were old. If we were to target ads solely based on that information, our targeting would not be very effective, because the level of interest and recency would not be taken into account.

But RANKING does not rely solely on Personal Signals – remember, Real-Time Signals are also taken into account.

Sure, I’m interested in going on holiday, but am I interested in going on holiday right now?

Instead of simply guessing that someone who has the interest ‘Travelling’ attached to their profile might be interested in an ad for plane tickets to Berlin, now RANKING has access to information like this:

Facebook pixel data after performing a search on
Facebook pixel data after performing a search on

This is the information that sent to its Facebook pixel after I performed a search on their website.

Information on the destination, check-in and out dates, preferred hotel star ratings, number of people travelling – it was all given to Facebook.

So, if tomorrow RANKING is given ads for the San Diego Zoo or for airplane tickets to Berlin, guess which ad it’s going to choose to show me?

Machine learning & signals

Have you ever received an ad for a ride-sharing service just when it started to rain? Or an ad for a meditation app when you were in bed but couldn’t fall asleep?

Your device, GPS location, the time of day, the hourly weather report in your area, your IP address… all of these can be used as real-time signals.

The content you’ve engaged with, the videos you’ve watched, the websites you’ve browsed… all of these can be used as personal signals.

Are there any breaking news stories? 

What are your local Facebook connections interested in right now? Especially the ones who have similar interests and behavioral patterns as you. 

Maybe RANKING will check if you’d be interested in those stories too.

Have you ever heard stories from your friends, how they were chatting about something and then one of them saw an ad for it later that day? No, there’s no need for Facebook to listen to your microphone… 

There is already so much data on you, and everyone around you, available anyway.

Povilas KrikščiūnasPovilas Krikščiūnas