Protocols

⏱ 6 min read

In one sentence: A protocol is a set of rules that computers agree on, so they can send messages to each other and understand them.

Why should I care?

Look at a full web address, such as https://developer.mozilla.org. The first part, https, contains the letter P. It stands for protocol: a set of rules your browser and a website use to talk.

Every time you open a page, your device follows many protocols at once. Without them, two connected computers would not understand each other.

Analogy

Think of a phone call. You and the other person follow rules without thinking about them:

  1. One person says "Hello", and the other answers.
  2. You take turns to speak, in the same language.
  3. If you do not hear something, you say "Sorry, can you repeat that?"
  4. You say "Goodbye" before you end the call.

A protocol is a set of rules like this, for computers.

Where the analogy breaks down: people can guess. If a friend answers the phone in a strange way, you still understand. Computers do not understand a message the way a person does. Each message has an exact meaning, and both sides must agree on the rules first. Also, the protocols of the internet are written down in exact detail, in public documents.

How it actually works

What a protocol says

In What is a Network?, you saw that a network connects devices. A connection is not enough. The devices must also agree on the format of the information they send. MDN, a website that documents how the web works, calls the set of rules that defines that format a protocol.

One encyclopedia says a protocol sets the rules for:

  • the form of each message (where each part goes),
  • the meaning of each message,
  • the timing: when messages are sent,
  • and ways to recover from errors.

An example: asking for a web page

Your browser uses a protocol called HTTP (HyperText Transfer Protocol) to ask for a web page. (Hypertext is text with links to other texts. HTTPS is an encrypted, secure version of HTTP.) The computer that stores the page and sends it out is called a server.

Like a phone call, it is a question and an answer. MDN shows an example. The browser sends a request, a message that asks for something:

Diagram: the first two lines of an HTTP request. The first line asks for the page at the path /. The second line names the server.

GET / HTTP/1.1
Host: developer.mozilla.org
... (more lines)
  • GET / asks for the page at the path /. A path says which page or file on the server you want. / means the top, or root, of the server.
  • HTTP/1.1 names the version of the protocol.
  • Host: names the server the request is going to: here, the website developer.mozilla.org.

The server sends back a response. Here are two of its lines:

Diagram: two lines from an HTTP response. The first line says the request succeeded. The second line says what kind of content follows.

HTTP/1.1 200 OK
Content-Type: text/html
... (more lines, then the page itself)

The number 200 is a status code. It means "the request succeeded". Content-Type: text/html says what kind of content follows: a web page. Another status code you may know is 404. It means the server cannot find the page or file you asked for.

Both sides know these rules before they start. That is why they understand each other.

Protocols work in layers

Several protocols work together, each with its own job. They are stacked in layers, and each layer relies on the one below it. When you open a web page:

Protocols stacked in layersThree protocols stacked in layers, each relying on the one below it. HTTP is on top: what the browser and the server say. TCP is in the middle: all the pieces arrive, without errors, and in the right order. IP is below it: addresses that name each device. At the bottom is the network itself: cables and radio waves.

relies on

relies on

relies on

HTTP: what browser and server say

TCP: pieces arrive, without errors, in order

IP: addresses that name each device

The network: cables and radio waves

  • HTTP is on top. It is usually sent over TCP. (A newer version, HTTP/3, uses a different protocol instead of TCP.)
  • TCP (Transmission Control Protocol) makes sure the data arrives "reliably" and "error-free", in the same order as it was sent. The data travels in small pieces called Packets.
  • IP (Internet Protocol) uses a number for each device, called an IP address, so data can be sent to the right device.

(This is simplified. There are more layers and many more protocols. You will meet TCP and IP again in TCP/IP.)

How it came to be

ARPANET was an early computer network. In 1969, S. Crocker, then at UCLA, started a series of notes called Request for Comments, or RFC.

In December 1970, a group led by S. Crocker finished the first protocol for ARPANET computers to talk to each other. It was called the Network Control Protocol (NCP). On January 1, 1983, the ARPANET changed from NCP to TCP/IP (TCP and IP together). All computers on it had to change at the same time.

Today, an organization called the IETF (Internet Engineering Task Force) publishes the internet's official protocol rules, called standards, as RFCs. Once published, they are free for anyone to read.

🧪 Try it in your browser

You will see a status code that a server sends back. You need a computer with a keyboard. These steps change nothing.

  1. In Chrome, Edge or Firefox, open this link, a page that does not exist: developer.mozilla.org/en-US/this-page-does-not-exist. You should see a page with the words "Page not found".
  2. Open the network tool:
    • Chrome and Edge: press Ctrl + Shift + J (Mac: Cmd + Option + J). A panel of developer tools opens in the browser window, showing a part called the Console. Click the tab named Network. In Edge, if you do not see it, click the More tools button and choose Network.
    • Firefox: press Ctrl + Shift + E (Mac: Cmd + Option + E).
  3. The list is empty at first. The tool only records while it is open. Reload the page with the browser's reload button.
  4. Rows appear. Each row is one request: one file the browser asked for. A page is often made of many files, such as pictures. The first row is usually the page itself.
  5. Find the column named Status. In the first row, it shows 404: "not found".
  6. Look at the other rows. Many of them show 200: those files were found. You may also see other numbers. That is normal.
  7. When you are done, close the browser tab with the "Page not found" page.

On a phone: open the same link. The "Page not found" message is how the website shows you the 404 status code.

Common misunderstandings

  • "A protocol is a program." No. A protocol is a set of rules. Programs, such as your browser, follow those rules.
  • "The internet uses one protocol." No. Many protocols work together in layers.
  • "A cable is enough for two computers to talk." No. A cable only carries the signal. Both computers must also follow the same protocol to understand the messages.

Recap

  • A protocol is a set of rules for messages: their form, their meaning, when to send them and what to do when something goes wrong.
  • Protocols work in layers. For a web page, HTTP usually runs over TCP, and TCP runs over IP.
  • Internet protocols are written down in public documents called RFCs, a series that started in 1969.

Sources

Written with AI · Reviewed by AI · Not yet checked by a human

Found a mistake, or something you did not understand? Report a problem.