> For the complete documentation index, see [llms.txt](https://mominur.gitbook.io/mominur-notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mominur.gitbook.io/mominur-notes/random-topics/how-dns-resolution-works.md).

# How DNS Resolution Works

When you type [**www.facebook.com**](http://www.facebook.com/) in your browser, your computer cannot understand domain names directly. It only communicates using **IP addresses**. DNS (Domain Name System) is like the internet’s phonebook, translating human-readable domain names into machine-readable IP addresses. Let’s go step by step.

***

### 1. Browser Cache Check

The first step happens in your browser. Modern browsers store **recently visited domain-IP mappings** in a cache.

**Example:**

* You type: `www.facebook.com`
* Browser checks if it has the IP stored, e.g., `157.240.22.35`.
* If the IP exists → browser uses it immediately.
* If not → browser queries the operating system.

***

### 2. Operating System (OS) Cache

If the browser cache doesn’t have the IP, your computer checks its **OS-level cache**, which also stores previously resolved domain-IP mappings.

**Example:**

* OS finds the cached IP → returns it to the browser.
* If not found → query goes to a **recursive DNS resolver**.

***

### 3. Recursive DNS Resolver

This is usually provided by your **ISP** (Internet Service Provider) or a public DNS like Google DNS (`8.8.8.8`). Its job is to find the IP address for the requested domain.

**Example:**

* Browser asks resolver: “What is the IP of [www.facebook.com?”](http://www.facebook.com/?%E2%80%9D)
* Resolver begins a sequence of queries to locate the IP.

***

### 4. Root Name Server

The recursive resolver first contacts a **root name server**. There are 13 sets of root servers worldwide. Root servers don’t know Facebook’s IP but can direct the resolver to the **Top-Level Domain (TLD) server**.

**Example:**

* Root server → This is a `.com` domain. Ask the `.com` TLD server.

***

### 5. TLD Name Server

The **TLD server** manages all domains under a specific extension like `.com`. It doesn’t know the exact IP, but it knows which **authoritative name server** to ask.

**Example:**

* `.com` TLD server → For facebook.com, contact ns1.facebook.com (authoritative server).

***

### 6. Authoritative Name Server

The **authoritative server** has the definitive IP address for the domain.

**Example:**

* `ns1.facebook.com` → returns the IP: `157.240.22.35`
* This is the server that hosts the Facebook website.

***

### 7. Returning the IP

The recursive resolver sends the IP back to your **OS**, which passes it to the **browser**. Both may cache this IP for future visits to speed up access.

***

### 8. Browser Connects to Server

With the IP in hand, your browser can now establish a **TCP connection** to Facebook’s server.

* If the site uses HTTPS (like Facebook), a **TLS/SSL handshake** happens to secure the connection.
* Browser then sends an **HTTP GET request** for the homepage.

***

### 9. Server Response

Facebook’s server processes the request and sends back:

* **Status code** (200 OK)
* **Headers** (cookies, content type)
* **Content** (HTML, CSS, JS, images)

***

### 10. Browser Rendering

* Browser parses HTML, CSS, and JS.
* Makes additional requests for images, scripts, fonts, etc.
* Renders the fully functional Facebook homepage for the user.

***

Without DNS, we would have to remember **numerical IP addresses** instead of human-readable domain names like `www.facebook.com`.
