How does a face recognition system work?

Authors
How does a face recognition system work?

A Face Recognition system finds a face in a photo, turns it into a list of numbers called a faceprint, and compares it with saved faceprints to tell whose face it is.

In this blog, we will learn about how a Face Recognition system works. We will also see how the system finds and aligns a face, how it turns the face into a faceprint, how it compares two faceprints, how it learns, the difference between one-to-one and one-to-many matching, and where it works well and where it fails.

We will cover the following:

  • What is Face Recognition?
  • Face Detection vs Face Recognition
  • Step 1: Finding the Face
  • Step 2: Aligning the Face
  • Step 3: Turning a Face into Numbers
  • The Faceprint
  • Step 4: Comparing Two Faces
  • How the System Learns
  • Enrollment vs Recognition
  • One-to-One vs One-to-Many
  • A Full Walkthrough with Numbers
  • Where Face Recognition is Used
  • Challenges and Limitations

I am Amit Shekhar, Founder @ Outcome School, I have taught and mentored many developers, and their efforts landed them high-paying tech jobs, helped many tech companies in solving their unique problems, and created many open-source libraries being used by top companies. I am passionate about sharing knowledge through open-source, blogs, and videos.

I teach AI and Machine Learning at Outcome School.

Let's get started.

What is Face Recognition?

Face Recognition is a system that looks at a face and answers one question: "Whose face is this?"

So, we show a photo to a computer, and the computer tells us which person it belongs to.

We do this every day without thinking. We see a friend across the street, and in a fraction of a second, our brain says "that is Ravi". We did not measure anything. We just knew.

A Face Recognition system tries to do the same thing. But a computer cannot "just know". A computer only understands numbers. So the whole job of a Face Recognition system is to turn a face into numbers, and then compare those numbers.

We will learn about each step in detail.

Face Detection vs Face Recognition

Before going further, we must clear up two words that sound similar but mean very different things.

Face Detection answers the question: "Is there a face here, and where is it?"

Face Recognition answers the question: "Whose face is this?"

Let's say we take a group photo at a party. Face Detection draws a box around each face in the photo. It does not know any name. It only knows "here is a face, and here is another face".

Face Recognition is the next step. It takes each face and says "this one is Ravi, this one is Sita".

So Detection comes first. Recognition comes after. We cannot recognize a face until we have found it.

Now that we understand the difference, let's walk through the full journey, one step at a time. We can see the full flow in a diagram like below:

            Raw Photo
                ↓
+-----------------------------+
|     Step 1: Detection       |
|   find where the face is    |
+-----------------------------+
                ↓
+-----------------------------+
|     Step 2: Alignment       |
| straighten and resize face  |
+-----------------------------+
                ↓
+-----------------------------+
|      Step 3: Numbers        |
| neural network makes a      |
| faceprint                   |
+-----------------------------+
                ↓
+-----------------------------+
|      Step 4: Compare        |
| measure distance to a saved |
| faceprint                   |
+-----------------------------+
                ↓
     Same person? Yes or No

Here, we can see that the photo enters at the top and travels down through four steps. Each step hands its result to the next step, and the final answer is a simple yes or no.

Step 1: Finding the Face

A camera gives us a full picture. That picture has a background, a wall, other people, or a coffee cup on the table.

The system does not care about any of that. It only wants the face.

So the first step is Face Detection, which means finding the exact spot where the face is.

The system slides its attention across the whole image and asks at every spot, "does this look like a face?" A face has a common pattern. There are two eyes near the top, a nose in the middle, and a mouth below. These parts sit in a fixed arrangement.

When the system finds an area with this pattern, it draws a box around it. We call this a bounding box, which means a rectangle that wraps tightly around the face.

Now the system can throw away everything outside that box. The background is gone. The coffee cup is gone. We are left with just the face.

Face Detection is one special case of finding objects in an image, and we have a detailed blog on How does Object Detection work? that explains this in depth.

Step 2: Aligning the Face

We have the face now. But there is a small problem.

In real photos, faces are never perfectly straight. Sometimes the head is tilted. Sometimes the person looks slightly to the side. Sometimes the face is small and far away, and sometimes it is big and close.

If we compare a tilted face with a straight face, the comparison becomes unfair. The same person could look like two different people just because of the angle.

So, here comes Face Alignment to the rescue.

Face Alignment means rotating, scaling, and centering the face so that it always sits in a standard position.

To do this, the system first finds a few key points on the face. We call these landmarks. The corners of the eyes, the tip of the nose, and the corners of the mouth are common landmarks.

Once the system knows where the eyes are, it rotates the face until both eyes sit on a level line. It also resizes the face to a fixed size, for example a small square.

Now every face that enters the system looks neat and standard. A tilted face becomes straight. A small face becomes the right size.

This is how we make the comparison fair for everyone.

Planning your move into AI?

No matter which tech domain you work in today, with your effort, you can transition to these roles:

  • AI Engineer
  • Forward Deployed Engineer
  • AI Agent Engineer
  • Harness Engineer
  • Voice AI Engineer
  • AI Architect
  • LLM Engineer
  • LLM Inference Engineer
  • Gen AI Engineer
  • MLOps Engineer
  • ML Engineer
  • Deep Learning Engineer

Our AI and Machine Learning Program at Outcome School takes you there.

Step 3: Turning a Face into Numbers

A computer cannot understand "a face". It only understands numbers. So we must convert the face into numbers.

A naive idea would be to use the raw pixels. Every image is made of tiny dots called pixels, and each pixel has a number for its color. So we could just collect all those pixel numbers and call that our description of the face.

But this idea fails.

If the light changes, the pixel numbers change. If the person smiles, the pixel numbers change. If the camera moves a little, the pixel numbers change. The same person would produce completely different numbers every time. That is useless for recognition.

We needed a better solution, and a special kind of model was introduced to solve this problem.

The system uses a neural network, which is a model loosely inspired by how the human brain learns patterns. We feed the aligned face into this neural network, and it outputs a short list of numbers that describe the face.

These numbers are not random. They capture the features of a face, roughly things like how far apart the eyes are, how wide the nose is, and the shape of the jaw. The network packs all of this into a compact list of numbers.

The network is trained so that the same person always gets very similar numbers, even under different light, different angle, or different expression. And two different people get very different numbers.

Let's give this list of numbers its proper name.

The Faceprint

The list of numbers that describes a face has a special name. It is called a face embedding. Many people simply call it a faceprint.

Think of a fingerprint. Your fingerprint is a unique pattern that belongs to you and only you. A faceprint is the same idea, but for your face. It is a unique signature made of numbers.

Let's say a faceprint is a list of 128 numbers. So one face becomes something like this:

[0.12, -0.88, 0.34, 0.05, -0.41, ... , 0.77]

Here, we can see that the face is now just a row of numbers. There are no eyes, no nose, no smile. Only numbers.

This is useful, because numbers are easy to store and easy to compare. We do not store your actual photo for matching. We store this list of numbers.

Now we have a way to describe any face as numbers. The next question is, how do we compare two of these lists?

Step 4: Comparing Two Faces

We now have faceprints, which are lists of numbers. To recognize a person, we compare two faceprints and ask, "are these close to each other?"

Let's build the intuition with a very simple example.

Suppose we describe people with just two numbers, height and weight. Two people who are truly similar will have numbers that are close together. Two very different people will have numbers that are far apart.

A faceprint works the same way, just with many more numbers, for example 128 of them instead of 2.

So the system measures the distance between two faceprints. Distance here simply means "how far apart are these two lists of numbers".

If the distance is small, the two faces are very similar, so they are probably the same person.

If the distance is large, the two faces are very different, so they are probably different people.

But how small is small enough? For this, the system uses a threshold, which means a fixed cut-off line that we decide in advance.

Here is the rule:

  • If the distance is below the threshold, the system says "same person".
  • If the distance is above the threshold, the system says "different person".

For example, let's say the threshold is 0.6. If two faceprints have a distance of 0.3, that is below 0.6, so it is a match. If the distance is 0.9, that is above 0.6, so it is not a match.

Let's see it in a diagram like below:

Faceprint A + Faceprint B
            ↓
    measure distance
            ↓
     distance value
            ↓
   is distance < 0.6 ?
            ↓
  yes: Same person (match)
  no: Different person (no match)

Here, we can see that two faceprints go in, the system measures the distance between them, and then a single threshold of 0.6 decides the answer. Below the line is a match, above the line is not a match.

This is how the system finally decides who is who.

A quick note for you

No matter which tech domain you work in, get familiar with these topics:

  • LLM
  • RAG
  • MCP
  • Agent
  • Fine-tuning
  • Quantization

We put it all together in one video:

AI Engineering Explained: LLM, RAG, MCP, Agent, Fine-Tuning, and Quantization

No need to stop reading - bookmark it and watch later when you get time. Future you will thank you.

Now, let's get back to the topic.

How the System Learns

A natural question arises. How does the neural network learn to give the same person similar numbers and different people different numbers?

The answer is training.

We show the network a huge number of face photos, often millions of them, with the correct person labeled for each one. In a popular training method, the network looks at three faces at a time.

It looks at one photo of a person, another photo of the same person, and a photo of a different person.

The parameters of the network then get updated with one instruction. Pull the two same-person faceprints closer together, and push the different-person faceprint farther away. This method is called triplet loss.

This updation happens millions of times. Slowly, the network gets better and better at this single goal.

After enough training, the network becomes an expert at producing faceprints. We can then use it on faces it has never seen before, and that too without retraining.

If we want to go deep into Neural Networks, Embeddings, Contrastive Learning, and Loss Functions, and even build a Neural Network from scratch, check out our AI and Machine Learning Program at Outcome School.

Enrollment vs Recognition

A Face Recognition system works in two stages, and we must understand both.

Enrollment is the first stage. This is when the system learns who you are. For example, when you set up Face Unlock on a phone, the phone takes a few pictures of your face, turns them into a faceprint, and saves that faceprint. This saved faceprint becomes your reference.

Recognition is the second stage. This happens every time you use the system after that. When you raise the phone to unlock it, the camera captures your face, creates a fresh faceprint, and compares it with the saved faceprint.

If the fresh faceprint is close enough to the saved one, the phone unlocks.

Let's see both stages in a diagram like below:

ENROLLMENT (done once)
----------------------
Your face
    ↓
faceprint
    ↓
save it as the reference


RECOGNITION (done every time)
-----------------------------
Your face
    ↓
fresh faceprint
    ↓
compare with saved reference
    ↓
close enough? unlock

Here, we can see that enrollment happens only once and saves your reference faceprint. Recognition then runs every time you use the system, making a fresh faceprint and comparing it with that saved reference.

So we enroll once, and we recognize many times.

One-to-One vs One-to-Many

There are two ways the comparison can happen, and they solve two different problems.

One-to-One matching answers the question, "are you who you claim to be?"

Phone Face Unlock is a one-to-one match. The phone already knows whose phone it is. It only needs to check your fresh faceprint against one saved faceprint, which is yours. This is also called verification.

One-to-Many matching answers a bigger question, "who among all these people are you?"

Imagine an office with one thousand employees. A camera at the gate captures a face. The system does not know who walked in. So it compares this one fresh faceprint against all one thousand stored faceprints and picks the closest match. This is also called identification.

Finding the closest faceprint among many stored faceprints is a nearest neighbor search, and we have a detailed blog on How does Approximate Nearest Neighbor (ANN) search work? that explains how this search is done fast at scale.

Verification compares one against one. Identification compares one against many.

Both use the exact same idea of faceprints and distance. Only the number of comparisons changes.

Stay updated: Subscribe to our newsletter to get our latest AI and Machine Learning blogs straight to your inbox.

A Full Walkthrough with Numbers

Let's tie everything together with a simple story, step by step.

Suppose Ravi wants to unlock his phone.

Step 1: Ravi set up Face Unlock last week. The phone created his faceprint and saved it. Let's call it Ravi_saved.

Step 2: Today, Ravi lifts the phone. The camera captures the current frame, which has Ravi's face plus some background.

Step 3: Face Detection finds the face and draws a box around it. The background is removed.

Step 4: Face Alignment straightens the face and resizes it to a standard square.

Step 5: The neural network turns the aligned face into a fresh faceprint. Let's call it Ravi_now.

Step 6: The system measures the distance between Ravi_now and Ravi_saved. Suppose the distance comes out to 0.25.

Step 7: The threshold is 0.6. Since 0.25 is below 0.6, the system declares a match.

The phone unlocks.

Now suppose a stranger picks up Ravi's phone and looks at it. The stranger's fresh faceprint will be far from Ravi_saved. Suppose the distance is 0.95, which is above 0.6. So the phone stays locked. The stranger is rejected.

Where Face Recognition is Used

Let's see where it shows up in real life.

  • Phone unlock: The most common use.
  • Airport gates: Faces are matched against passport photos to speed up boarding.
  • Photo apps: Apps group all photos of the same person together, so you can find every photo of one friend.
  • Attendance systems: Offices and schools mark attendance by recognizing faces instead of signing a register.
  • Payments: Some systems let you pay by simply showing your face.
  • Security and access: Doors that open only for recognized people.

In every case, the core idea is the same. Turn the face into a faceprint, compare it with a stored faceprint, and decide using a threshold.

Challenges and Limitations

Face Recognition is not perfect. We must understand its weak spots.

Lighting and angle: A very dark room or an extreme side angle can confuse the system. Good alignment helps, but it does not fix everything.

Look-alikes: Identical twins can have very close faceprints. The system can struggle to tell them apart.

Aging and change: Faces change over time. A heavy beard, new glasses, or many years passing can increase the distance and cause a wrong rejection.

Spoofing: Someone could try to fool the system by holding up a photo or a video of your face. To stop this, good systems add liveness detection, which means a check to confirm a real, live person is present and not a flat photo. For example, the system may ask you to blink or it may use a depth sensor that sees the 3D shape of a real face.

Fairness and privacy: A system trained mostly on one type of face may work less well on other faces. This is a real concern, and good teams test their systems across many kinds of people. Faceprints are also sensitive personal data, so they must be stored safely and used with consent.

Now we must have understood how a Face Recognition system works, from a raw photo, to a clean aligned face, to a faceprint made of numbers, to a final match decided by distance and a threshold.

Frequently Asked Questions

Does a face recognition system store my photo?

No. For matching, the system does not store your actual photo. It stores your faceprint, which is a list of numbers that describes your face, because numbers are easy to store and easy to compare. Faceprints are still sensitive personal data, so they must be stored safely and used with consent.

Can face recognition be fooled by a photo of my face?

It can be, which is why good systems add liveness detection. Liveness detection is a check that confirms a real, live person is present and not a flat photo or a video. For example, the system may ask you to blink, or it may use a depth sensor that sees the 3D shape of a real face.

Can face recognition tell identical twins apart?

Not always. Identical twins can have very close faceprints, so the distance between their faceprints can be small. Since the system calls it a match when the distance is below a threshold, it can struggle to tell twins apart.

Does the system need retraining to recognize a new person?

No. After enough training, the network becomes an expert at producing faceprints, and we can use it on faces it has never seen before without retraining. A new person only needs to enroll, which means the system creates their faceprint once and saves it as the reference.

That's it for now.

Thanks

Amit Shekhar
Founder @ Outcome School

You can connect with me on:

Follow Outcome School on:

Read all of our high-quality blogs here.