TodayTools

Hypertext Transfer Protocol

How HTTP works

Asks a server for a page and gets it back

Donate
L7ApplicationPort 80TCP
What brings you here?

Watch it happen

How much detail

Typing a web address and getting the page, from name lookup to the first byte.

Your laptop
Home router
Internet
DNS resolver
Web server
Wi-FiInternetLookupSetupRequestControlResponse

5 steps, 9 packets

First up: You press Enter. Press Play to watch it happen, one step at a time.

0 of 50/5

What is HTTP?

HTTP is the language browsers and web servers speak. The browser sends a request (get me this page, save this form) and the server sends back a response with a status code, some headers and usually a body such as HTML, an image or JSON.

Every app that talks to a server, from your bank app to a smart TV, uses HTTP or its secure form HTTPS. Learning its request and response shape explains most of what you see in browser developer tools.

Think of it like this. HTTP is like ordering at a counter. You say exactly what you want (GET the menu, POST my order), and the clerk answers with a code (here you go, sold out, wrong counter) and the item. Each order is separate: the clerk does not remember you unless you show a token, which is what cookies are.

Step by step

Normal

5 steps

Typing a web address and getting the page, from name lookup to the first byte.

  1. 1

    You press Enter

    The browser reads the address

    The browser splits http://www.example.com/index.html into a scheme (http), a host name and a path. It needs the server's IP address before it can send anything.

  2. 2

    DNS lookup

    Name becomes an IP address

    The laptop asks a DNS resolver for the A record of www.example.com. The answer is cached, so the next visit skips this step.

  3. 3

    TCP connection

    Three packets open a reliable link

    SYN, SYN-ACK and ACK set up a connection on port 80. Both sides agree on starting numbers so they can track every byte.

  4. 4

    Request

    GET /index.html

    The browser sends one text request. The Host header names the site, because one server often hosts many.

  5. 5

    Response

    200 OK and the page

    The server answers with a status line, headers and the HTML. Large replies are split into many TCP segments and put back together in order.

404 Not Found

3 steps

The server is reached, but the page does not exist.

  1. 1

    Connection ready

    DNS and TCP already done

    The browser reuses the open connection from a moment ago, so no new lookup or handshake is needed. This is what keep-alive saves.

  2. 2

    Request

    GET /old-page.html

    The link points to a page that was moved or deleted.

  3. 3

    404 reply

    The server says it has no such page

    4xx codes mean the request was the problem, not the server. Many sites send a friendly HTML page with the 404 so you can find your way.

Someone listening

3 steps

Why plain HTTP is unsafe on shared Wi-Fi: anyone on the path can read it.

  1. 1

    Login form sent

    POST with a password

    The site uses http://, so the form goes out as plain text.

  2. 2

    Copy on the air

    Wi-Fi is a shared radio

    Anyone in range on an open network can capture the frames. With HTTP there is nothing to decode: the password is right there.

  3. 3

    The fix

    Use HTTPS

    HTTPS wraps the same request in TLS, so the stranger sees only scrambled bytes and the server name.

Myths and mix-ups

  • HTTP is not the same as the web page: it is the delivery, HTML is the content.
  • A 404 does not mean the server is down; the server answered, the page is just missing.
  • Plain HTTP is not private, even with a password field on the page.
  • HTTP/2 and HTTP/3 keep the same methods and status codes; they change how bytes travel.

Try it yourself

Run these on your own computer to see HTTP at work.

  • See request and response headers

    curl -v http://example.com/

    Lines starting with > are what you sent, < is what came back.

  • Headers only

    curl -I https://example.com/

    Sends a HEAD request: the response without the body.

  • In the browser

    F12, then Network tab, then reload

    Click any row to see its method, status and headers.

HTTP at a glance

Layer
Application (7)
Default port
80 (HTTPS uses 443)
Transport
TCP (HTTP/3 uses QUIC)
Format
Text headers plus an optional body
Common methods
GET, POST, PUT, PATCH, DELETE, HEAD
Stateless
Yes, cookies add memory
First version
1991 (HTTP/0.9)

Defined inRFC 9110RFC 9111RFC 9112

Header fields

What HTTP puts in its messages, with example values from the stories above.

HTTP/1.1

Method
GETGET asks for a resource without changing anything.
Path
/index.html
Host
www.example.comOne server can host many sites, so the request names the one it wants.
Status
200 OK2xx means success. 3xx is a redirect, 4xx is your mistake, 5xx is the server's.
Content-Type
text/html; charset=utf-8
Cache-Control
max-age=3600The browser may reuse this copy for one hour.
Body
user=ravi&password=sunrise42Readable by anyone who sees the packet.

Test yourself

Question 1 of 5Score 0

Which status code means the page was not found?

Questions people ask

What is the difference between HTTP and HTTPS?

HTTPS is HTTP sent inside a TLS connection. The requests and responses are the same, but nobody between you and the server can read or change them.

Which port does HTTP use?

Port 80 by default. HTTPS uses port 443. A URL can name another port, like http://example.com:8080.

Is HTTP stateless?

Yes. Each request stands alone. Sites remember you with cookies or tokens that the browser sends with every request.

What are HTTP methods?

Verbs that say what you want: GET reads, POST creates or submits, PUT replaces, PATCH updates part, DELETE removes and HEAD gets only the headers.

What do HTTP status codes mean?

1xx is information, 2xx success, 3xx redirect, 4xx a problem with the request and 5xx a problem on the server.

Donate