What happens when you type any URL in the browser and press enter?

Praveen Mekala
Nerd For Tech
Published in
5 min readDec 5, 2020

--

Well, many of us must be curious to know “what happens when we type any URL in a browser and press enter ?”. Actually, this is really a very big question and takes months or even years to understand each concept involved in this. This article gives you the basic idea about how the request is processed and the response will be received.

Let's say we are accessing “http://www.google.com”, here is how we get the response:

  1. Finding the IP address of a website (URL) in the different levels of cache.
  2. Creates a TCP/UDP connection with the destination Google server.
  3. Send the GET|www.google.com request through TCP/UDP to the google server.
  4. Google server processes the received request and sends the response back.
  5. The browser understands & displays the response.

1. Finding the IP address of a website (URL)

In general domain names are human-readable and easier to remember. But we need destination IP addresses(which will help in packet forwarding) instead of human-readable domain names to process the request. DNS does the work for us i.e. DNS helps us by storing each domain name and its associated IP addresses. Before we get the IP address directly from DNS servers there are multiple places (cache levels) from where we can get the IP address quickly. This is nothing but IP routing.

  1. Firstly, the browser will check its own DNS cache. Most of the browsers like Chrome, Firefox, etc maintain their own DNS cache level so that they can provide faster responses. We can check the browser DNS cache using these commands: Firefox browser - about:networking#dns & Chrome browser - chrome://net-internals/#dns.

The below image shows the DNS cache stored by the Firefox browser.

Screenshot of command: about:networking#dns from firefox browser

2. If the IP address is not cached in the browser, it continues to the next level i.e. to check OS cache. The browser will make a system call using getaddrinfo(). If the os caches the IP it returns otherwise it will continue.

3. The next level is to check the WiFi router cache(WiFi routers do have their own memory cache but in limited size). If not found the request continues.

4. The next level is to check the cable modem cache. If not found the request continues.

5. The next level is to check the ISP’s DNS cache. If the IP address is not found till this level, the ISP will perform the DNS recursive search until it finds the IP address or returns an error if not found. If multiple IP addresses are found for a domain name, the DNS round-robin algorithm selects one & returns.

A pictorial representation of all the above steps for DNS routing is shown below.

finally, we got the IP address for www.google.com as 172.217.14.196

2. Creates a TCP/UDP connection with the destination Google server

Once we find the IP address, we need a communication medium that carries our request data to the destination server. Here comes the role of TCP/IP. The client(browser) will perform TCP three-way handshake with the destination server to check whether the server is ready to accept requests & to agree to which protocols are being used etc. Once the handshake is completed and a TCP communication channel is opened, the client or server can send and receive the application data over the same connection until the client or server closes the connection.

3. Send the GET|www.google.com request through TCP to the google server.

Once the TCP connection is established with the destination server, we need to send our actual request i.e GET | http://www.google.com .

Let’s assume you want to write & post a letter to your friend. You will write the letter in a language where both of you can understand. You will post the letter by adding from & to address to reach your friend.

The same thing will be done at the client’s(browser) TCP layer. The request GET | http://www.google.com needs to be translated to a specific format so that the destination server can read understands & responds back. The TCP protocol's 4 layers i.e Application, Transport, Network & Datalink Layer will convert the request to meaningful binary data by adding source and destination port, address, header, mac address, request data type, response type, etc at each layer. The translated binary data will be divided into small units and transmitted over the network as packets.

We should notice that each packet will have a source and destination port, address, header, mac address, request data type, response type, etc. These details will help the receiver to convert into the original request.

In a nutshell, the client will send the GET | http://www.google.com request through TCP communication channel to the destination server as network packets.

4. Destination Google server receives, processes the request, and sends the response back.

Once the server receives the packets, the server's TCP layer helps to re-organize & convert these packets to the actual request sent by the client. The server processes the request and prepares the response in client requested format i.e. HTML, JSON, XML, etc & adds other details like response status, etc. Once the server is ready with the response, it will be sent back to the client.

5. The browser understands & displays the response.

Once the client receives the response from the server, the browser checks the response status code i.e 2xx(success response), 3xx(redirecting request),4xx(client error) 5xx(server error), etc.

The browser will try to translate the response based on the received response type. In our case it is HTML, so it will display the html page. If the response is cachable is will store the response in the browser cache.

--

--