docs.rodeo

MDN Web Docs mirror

How the web works

{{LearnSidebar}} 

{{NextMenu("Learn_web_development/Getting_started/Web_standards/The_Web_standards_model", "Learn_web_development/Getting_started/Web_standards")}} 

How the web works provides a high-level description of what happens when you use a web browser to navigate to a web page, explaining the magic that goes on behind the scenes to deliver the relevant code to your computer for the browser to assemble into something you can look at.

This theory is not essential to writing web code in the short term, but before long you’ll really start to benefit from understanding what’s happening in the background.

[!NOTE] This article does not cover how web browsers actually render code into web pages. That’s covered in How browsers load websites.

Prerequisites: Basic familiarity with your computer operating system, web browsers, and web technologies.
Learning outcomes:
  • Clients and servers and their roles in the web.
  • DNS and how it works at a high level.
  • The purpose of TCP/IP, HTTP, and packets.
  • HTTP syntax at a basic level.
  • Common HTTP response codes (e.g. 200, 301, 403, 404, and 500).
  • Basic components of a URL (protocol, domain, subdomain, path).

Clients and servers

Computers connected to the internet are called clients and servers. A simplified diagram of how they interact might look like this:

Two circles representing client and server. An arrow labelled request is going from client to server, and an arrow labelled responses is going from server to client

The other parts of the toolbox

The client and server we’ve described above don’t tell the whole story. There are many other parts involved, and we’ll describe them below.

For now, let’s imagine that the internet is a road. On one end of the road is the client, which is like your house. On the other end of the road is the server, which is like a shop you want to buy something from.

A black-and-white photo of a person crossing a road at a crosswalk

In order for data to get back and forth, we need the following things:

So what happens, exactly?

When you type a web address (which is technically part of a URL) into your browser address bar, the following steps occur:

  1. The browser goes to the DNS server and finds the real address of the server that the website lives on (you look up the address of the shop).
  2. The browser sends an HTTP request message to the server, asking it to send a copy of the website to the client (you go to the shop and order your goods). This message, and all other data sent between the client and the server, is sent across your internet connection using TCP/IP.
  3. If the server approves the client’s request, the server sends the client a “200 OK” message, which means “Of course you can look at that website! Here it is”, and then starts sending the website’s files to the browser as a series of small chunks called data packets (the shop gives you your goods, and you bring them back to your house).
  4. The browser assembles the small chunks into a complete web page and displays it to you (you get the goods home — new shiny stuff, awesome!).

DNS explained

Real web addresses (URLs) aren’t the nice, memorable strings you type into your address bar to find your favorite websites. They are special numbers that look like this: 192.0.2.172.

This is called an {{Glossary("IP Address", "IP address")}} , and it represents a unique location on the web. However, it’s not very easy to remember, is it? That’s why the Domain Name System was invented. This system uses special servers that match up a web address you type into your browser (like “mozilla.org”) to the website’s real (IP) address.

Websites can be reached directly via their IP addresses. You can use a DNS lookup tool to find the IP address of a website.

[!CALLOUT]

Try it out

  1. Go to the NsLookup.io DNS lookup tool, type in developer.mozilla.org, and press the button.
  2. In the results screen, copy the IP Address (the IPv4 address) to your system clipboard.
  3. Open a new browser tab, paste the IP Address into the address bar and press Enter/Return. You should see MDN load up, proving that the IP address points to it.

Packets explained

Earlier we used the term “packets” to describe the format in which the data is transferred between the client and server. What do we mean here?

Basically, when data is sent across the web, it is sent in thousands of small chunks. There are multiple reasons why data is sent in small packets, but most significantly:

HTTP basics

HTTP uses a simple language of verbs to perform actions such as making requests (see HTTP request methods). The HTTP GET method is the one normally used to make HTTP requests of the type described above. For example, a request for the MDN home page might look like this:

GET /en-US/ HTTP/2

Host: developer.mozilla.org

The response sent by the server might looks something like this:

HTTP/2 200

date: Tue, 11 Feb 2025 11:13:30 GMT
expires: Tue, 11 Feb 2025 11:40:01 GMT
server: Google frontend
last-modified: Tue, 11 Feb 2025 00:49:32 GMT
etag: "65f26b7f6463e2347f4e5a7a2adcee54"
content-length: 45227
content-type: text/html

<!doctype html> ... (the 45227 bytes of the requested web page HTML)

The full response is more complex than this, but we have omitted most of it for brevity. The main parts are as follows:

[!NOTE] See the MDN HTTP reference for a lot more detail on HTTP, if you are curious. An overview of HTTP is a good place to start.

Other status codes

Above, we met the 200 status code, which indicates that the HTTP request was successful. There are many HTTP status codes with specific meanings and uses, but you will only commonly see a few:

Components of a URL

Technically, web addresses that you type into the browser address bar form part of Uniform Resource Locators (URLs). URLs define the locations of unique resources on the internet.

A URL is a web address plus a protocol: for example, if you open a new tab in your browser, type in developer.mozilla.org into the address bar, and press Enter/Return, you will be redirected to a URL like the following one:

https://developer.mozilla.org/en-US/

The main parts of the URL are:

[!NOTE] There are a lot more components that can appear in URLs. See What is a URL? for more details.

See also

Credit

Street photo: Street composing, by Kevin Digga.

{{NextMenu("Learn_web_development/Getting_started/Web_standards/The_web_standards_model", "Learn_web_development/Getting_started/Web_standards")}} 

In this article

View on MDN