Testing Fundamentals · 3 min read

How the internet works: DNS explained

A beginner-friendly guide to understanding the Domain Name System (DNS) and its role in connecting users to websites.

beginner-friendly

What happens when you type a URL into your browser?

That’s a question worth asking — and one that comes up very often in job interviews. When you enter a web address like www.youtube.com into your browser, your computer doesn’t know how to find that website on its own. Instead, it relies on a system called the Domain Name System (DNS) to translate that human-readable address into an IP address that computers can understand.

Finding the IP address

The first step is to find the corresponding IP address. This is done through a process called DNS resolution. Your computer sends a request to a DNS server, which looks up the IP address associated with the domain name you entered. If the DNS server has the information cached, it will return the IP address immediately. If not, it will query other DNS servers until it finds the correct IP address.

Once your computer receives the IP address, it can then use that information to establish a connection with the web server hosting the website you want to visit.

What happens if the IP is not in cache?

If the IP address is not in the cache, the DNS server will perform a series of queries to find the authoritative DNS server for the domain. This involves checking various levels of DNS servers, starting from the root servers, then moving to top-level domain (TLD) servers, and finally reaching the authoritative server that holds the actual IP address for the domain.

TCP connection and HTTP request

Once your computer has the IP address, it can establish a TCP connection with the web server. This involves a process called the three-way handshake, where your computer and the server exchange messages to establish a reliable connection.

Because most websites today are served over HTTPS, a TLS handshake happens next. During this step, your computer and the server agree on how to encrypt the connection and verify the server’s identity, so the data exchanged afterward stays private and secure.

After the connection is secured, your computer can send an HTTP request to the web server, asking for the specific webpage or resource you want to access. The server then responds with the requested data, which your browser renders for you to see.

Displaying HTML and other resources

After receiving the HTTP response, your browser processes the HTML content and any associated resources like CSS, JavaScript, and images. It constructs the Document Object Model (DOM) and applies styles and scripts to render the webpage as intended.