DEV Community

Cover image for How the web works
Akabogu Michelle
Akabogu Michelle

Posted on

How the web works

HOW THE WEB WORKS
Every day we surf the Internet. We get information from every click and every search. But have we ever stopped to ask ourselves, where is this information gotten from? How does the computer get this information? How does a website appear on our screen after we type its name?
I am here to answer these questions and explain, in a simple way, how the web works.
IP Address
Every computer has an IP address, just like every phone with a SIM card has a phone number.
Think about it this way. If I want to call you, I need your phone number. Your phone number helps me reach the right person.
Computers work in a similar way. When one computer wants to communicate with another computer, it needs to know where to send the information.
That is what an IP address helps with.
For example:
192.168.1.10
This is an example of an IP address.
So we can think of it like this:
Phone → Phone Number
Computer → IP Address
Here is a practical way to know the IP address of your computer
If you are using a Windows computer:

  1. Press Windows Key + R
  2. Type cmd
  3. Press Enter
  4. Type ipconfig
  5. Press Enter You will see information about your network connection, including the IP address of your computer. For example: IPv4 Address: 192.168.1.10 Now we know how to find an IP address. But this brings us to another question: What is an IP address and what is it used for? What Is an IP Address? IP means Internet Protocol. An IP address is a number given to a device when it is connected to a network. It helps identify the device and helps information know where to go. Let's use an everyday example. Imagine I want to send a letter to my friend. I cannot just write, "Send this letter to John." The person delivering the letter needs to know where John lives. So I give them John's address. Computers work in a similar way. The IP address is like the address of a computer on a network. So when information is being sent from one computer to another, the IP address helps the network know where the information should go. But there is a problem. Imagine that every time we wanted to visit Google, we had to remember a number like: 142.250.x.x That would be difficult. Instead, we can simply type: www.google.com So now we have another question: What is www.google.com? (web address) What Is a Web Address? A web address is simply the address we type into a web browser when we want to visit a website. For example: www.google.com www.youtube.com www.wikipedia.org These are web addresses. You may also hear the word URL. URL means Uniform Resource Locator. Don't let the big name confuse you. A URL is simply an address used to locate something on the web. So when I open Chrome and type: www.youtube.com I am giving my browser the web address of the website I want to visit. But computers communicate using IP addresses. So if I type www.youtube.com, how does the computer know which IP address belongs to YouTube? This is where DNS comes in. What Is DNS? DNS means Domain Name System. In simple words, DNS helps turn a website name into an IP address. Think about the contacts on your phone. Let's say you want to call your friend John. You may not remember John's phone number, but you don't have to. You simply open your contacts and search for John. Your phone finds John's number for you. DNS works in a similar way. The website name is like John's name. The IP address is like John's phone number. So: Website Name → DNS → IP Address For example: www.youtube.com → DNS → YouTube's IP Address So when we type www.youtube.com, DNS helps our computer find the IP address connected to YouTube. But now you might be wondering: "Okay, but how does DNS actually find that IP address?" Let's break it down. How Does DNS Find the IP Address? Imagine you are looking for someone's house. You know the person's name, but you don't know their address. So you start asking questions. You ask someone: "Where does this person live?" Maybe that person doesn't know the exact house. They might say: "I don't know the exact house, but I know the area. Go there and ask someone else." You go to that area. Someone there points you to the correct street. Then someone on that street helps you find the exact house. DNS works in a similar way. There are different DNS servers that help find the correct address. DNS Resolver The first one we need to understand is the DNS Resolver. A DNS resolver is simply a server whose job is to find the IP address we are looking for. So when we type: www.youtube.com our computer is basically asking: "What is the IP address for this website?" The DNS resolver tries to find the answer. Sometimes, it already has the answer saved. This brings us to another word: Cache. What Is a Cache? A cache is simply a place where information is temporarily saved so it can be found faster later. Here's an easy example. Imagine your teacher gives you an important note. Instead of asking your teacher for the same note every time you need it, you save it in your notebook. The next time you need it, you just open your notebook. That's basically what a cache does. A DNS resolver can temporarily save an IP address it found earlier. So if someone asks for www.youtube.com and the resolver already has the answer saved, it can give the answer quickly. But what happens if it doesn't have the answer? It has to go and look for it. And this is where the Root Server comes in. Root Server The Root Server is like the starting point at the top of the DNS system. But here's something important: the Root Server usually does not give us the exact IP address of YouTube. Instead, it helps point the DNS resolver in the right direction. Let's say we are looking for: www.youtube.com The Root Server looks at the address and notices that it ends with: .com It basically tells the DNS resolver: "You're looking for a .com website? Go and ask the .com TLD server." So the Root Server helps us know where to look next. What Is a TLD? TLD means Top-Level Domain. It is basically the ending part of a website address. For example: www.youtube.com Here, .com is the TLD. Other examples include: wikipedia.org → .org example.net → .net We also have country-related TLDs: .ng → Nigeria .uk → United Kingdom So when the Root Server sees www.youtube.com, it knows that we need to go to the .com TLD server. TLD Server Now we get to the TLD Server. The TLD server deals with websites that use that particular ending. So the DNS resolver goes to the .com TLD server and asks: "I'm looking for www.youtube.com. Where should I go?" The TLD server doesn't normally give us the final IP address. Instead, it basically says: "I know which DNS server is responsible for youtube.com. Go and ask that server." So it points us to the next place. And that brings us to the Authoritative DNS Server. Authoritative DNS Server The name sounds complicated, but the idea is actually simple. The Authoritative DNS Server is the server that has the actual DNS information for a particular website or domain. So the DNS resolver goes to the server responsible for: youtube.com and asks: "What is the IP address for www.youtube.com?" This server has the information and gives the IP address back. The answer then travels back to our computer. Now our computer finally knows where to send the request. The whole DNS journey can be understood like this: www.youtube.com ↓ DNS Resolver ↓ Root Server ↓ .com TLD Server ↓ Authoritative DNS Server ↓ IP Address Let's Make DNS Even Simpler If all those names still feel like a lot, think about it as finding someone's house. You know the person's name, but you don't know their address. You ask someone for help. They send you to the right area. Someone in that area sends you to the right street. Someone on that street helps you find the exact house. DNS does something similar. Website Name → Find the right place → Find the IP Address So when you type www.youtube.com, you don't need to know YouTube's IP address yourself. DNS does the searching for you. That is why DNS is often compared to a phonebook for the Internet. Types of IP Addresses Now that we understand what an IP address is, let's look at the main types. There are two main versions: IPv4 and IPv6. IPv4 IPv4 means Internet Protocol version 4. This is the type of IP address we commonly see written like this: 192.168.1.10 It has four groups of numbers separated by dots. Each group can contain a number from 0 to 255. IPv4 has been used for many years. But think about how many devices are connected to the Internet today. We have phones, laptops, tablets, smart TVs, cameras, game consoles, and many other devices. That's a lot of devices. Because IPv4 has a limited number of addresses, we needed a newer version. That is where IPv6 comes in. IPv6 IPv6 means Internet Protocol version 6. It was created to give us a much larger number of possible IP addresses. An IPv6 address looks something like this: 2001:db8:85a3::8a2e:370:7334 It looks complicated, but don't worry about memorizing it. The main thing to remember is: IPv4 → 32-bit address IPv6 → 128-bit address IPv6 gives us a much larger number of addresses for the growing number of devices connected to the Internet. Public and Private IP Addresses IP addresses can also be public or private. Let's use your home Wi-Fi as an example. You could have a phone, laptop, and smart TV connected to the same Wi-Fi. These devices can have their own private IP addresses inside your local network. For example: Phone → 192.168.1.10 Laptop → 192.168.1.11 TV → 192.168.1.12 A private IP address is mainly used inside a local network. A public IP address is used when communicating over the wider Internet. Your router helps connect the devices in your home to the Internet. So, in a simple way: Private IP → Used inside a local network Public IP → Used when communicating over the Internet How to Find the IP Address of a Website Now that we understand IP addresses and DNS, let's actually try to find the IP address of a website. One simple way is by using a command called: nslookup For example: nslookup google.com When we run this command, our computer basically asks: "What IP address belongs to google.com?" The DNS system then gives us the information it has. We can also use: ping google.com This can show the IP address that the website name is resolving to. This helps us understand that behind a simple website name like google.com, there is an IP address that computers use to communicate with that service. What Is a Client? Now we understand IP addresses and DNS. But another question comes up: Who is actually asking for the information? This brings us to the client. A client is simply a computer or program that asks another computer for information or a service. For example, when we open Chrome and type: www.youtube.com our browser is acting as the client. The browser is basically saying: "I want to visit YouTube. Please give me the information I need." So our: Computer → can be a client Phone → can be a client Web browser → can act as a client The important thing is that the client is the one making the request. What Is a Server? Now, if the client is asking for information, someone has to provide it. This is where the server comes in. A server is a computer or system that provides information or services to other computers. For example, when we visit YouTube, YouTube has servers that provide the information and services our browser is asking for. So we can think of it like a conversation: Client: "I want this webpage." Server: "Okay, here is the information." This is called the client-server model. How Do the Client and Server Communicate? Now our computer knows where the server is. But how does the browser actually talk to the server? This is where HTTP and HTTPS come in. What Is HTTP? HTTP means Hypertext Transfer Protocol. The name sounds complicated, but the basic idea is simple. HTTP is a set of rules that helps the browser and server communicate with each other. For example, when we visit YouTube, our browser sends a request to the server. The browser is basically saying: "Please give me this webpage." The server receives the request, understands what the browser wants, and sends something back. What Is HTTPS? HTTPS is the secure version of HTTP. HTTPS helps protect the information being sent between the browser and the server by using encryption. This is why you will usually see: https:// at the beginning of secure websites. So, in a simple way: HTTP → Communication between browser and server HTTPS → More secure communication between browser and server What Happens When We Open a Website? Now let's put everything together. Imagine I want to visit YouTube. I open my browser and type: www.youtube.com So what happens next? Step 1: We Enter the Web Address First, we type the web address into the browser. The browser now knows which website we want to visit. Step 2: DNS Finds the IP Address The computer needs to know the IP address connected to www.youtube.com. So DNS helps find that IP address. The DNS resolver may already have the answer saved. If it doesn't, it can go through the DNS system we talked about earlier. Step 3: The Computer Finds the Server Once the IP address is found, the computer now knows where to send its request. Step 4: The Browser Sends a Request The browser sends a request to the server using HTTP or HTTPS. It is basically saying: "I want this webpage." Step 5: The Server Receives the Request The server receives the request. It then works out what information it needs to send back. Step 6: The Server Sends a Response After processing the request, the server sends information back to the browser. This information can include things such as: • HTML • CSS • JavaScript • Images • Videos • Other files Step 7: The Browser Builds the Webpage Now the browser has received the information it needs. It starts putting everything together. HTML gives the webpage its structure. CSS controls how the webpage looks. JavaScript allows the webpage to respond to actions and do different things. The browser then puts everything together and displays the webpage on our screen. And all of this can happen very quickly. The Complete Process So, what actually happens when we type a website address? We type a web address ↓ The browser acts as the client ↓ DNS finds the IP address ↓ The computer finds the server ↓ The browser sends an HTTP/HTTPS request ↓ The server receives and processes the request ↓ The server sends a response ↓ The browser receives the information ↓ The browser puts HTML, CSS, JavaScript and other resources together ↓ The webpage appears on our screen Conclusion Every day, we use the Internet to search for information, watch videos, communicate, study, shop, play games, and do many other things. But behind every click and every search, there is actually a lot happening in the background. We have seen that an IP address helps identify a device and tells the network where information needs to go. We also learned that a web address is the address we type into our browser when we want to visit a website. Since IP addresses can be difficult for humans to remember, DNS helps us find the IP address connected to a website name. We also learned about the different parts of DNS, such as the DNS resolver, Root Server, TLD Server, and Authoritative DNS Server, and how they work together to find the correct IP address. After the IP address is found, our browser acts as a client and communicates with a server using HTTP or HTTPS. The server receives our request, processes it, and sends information back to our browser. The browser then uses HTML, CSS, JavaScript, and other resources to put everything together and display the webpage we see. So the next time you type a website address and a webpage suddenly appears on your screen, remember: It is not magic. 😂 There is a whole process happening behind the scenes. Web Address → DNS → IP Address → Client → Server → HTTP/HTTPS → Response → Browser → Webpage And that is, in a simple way, how the web works.

Top comments (0)