HTTP (HyperText Transfer Protocol) is the application-layer protocol that defines how clients and servers exchange data on the web. Every website visit, API call, and file download uses HTTP.
TL;DR HTTP is the set of rules that governs how browsers and servers communicate. A browser sends an HTTP request (e.g.,
GET /index.html); the server returns an HTTP response with a status code and content. HTTP is stateless — each request is independent. HTTPS is HTTP secured with TLS encryption. HTTP/1.1 (1997) opened one connection per request; HTTP/2 (2015) multiplexed many requests over one connection; HTTP/3 (2022) replaced TCP with QUIC for lower latency. Every web interaction uses HTTP at its core.
What is HTTP?
HTTP (HyperText Transfer Protocol) is an application-layer protocol that defines the format and rules for communication between clients (browsers, apps, APIs) and servers. It is the foundation of the World Wide Web.
HTTP operates on a request-response model:
- A client sends an HTTP request to a server.
- The server processes the request and returns an HTTP response.
HTTP is stateless — each request is completely independent. The server has no memory of previous requests from the same client. Cookies, sessions, and tokens are used to maintain state across requests at the application layer.
HTTP runs over TCP (HTTP/1.1 and HTTP/2) or QUIC/UDP (HTTP/3). HTTPS is HTTP with TLS encryption added at the transport layer.
The HTTP request-response cycle
HTTP request structure
GET /products?category=shoes HTTP/1.1Host: shop.example.comAccept: application/jsonAuthorization: Bearer eyJhbGci...User-Agent: Mozilla/5.0An HTTP request has four parts:
- Request line — method, path, HTTP version
- Headers — metadata about the request (host, content type, authentication)
- Blank line — separates headers from body
- Body (optional) — data sent with POST, PUT, PATCH requests
HTTP response structure
HTTP/1.1 200 OKContent-Type: application/jsonContent-Length: 342Cache-Control: max-age=3600
{"products": [...]}An HTTP response has:
- Status line — HTTP version, status code, reason phrase
- Headers — metadata about the response
- Blank line
- Body — the requested content
HTTP methods
HTTP methods (also called verbs) define the intended action of the request:
| Method | Purpose | Has body | Idempotent | Safe |
|---|---|---|---|---|
GET | Retrieve a resource | No | Yes | Yes |
POST | Create a resource or submit data | Yes | No | No |
PUT | Replace a resource entirely | Yes | Yes | No |
PATCH | Partially update a resource | Yes | No | No |
DELETE | Remove a resource | No | Yes | No |
HEAD | Same as GET but no response body | No | Yes | Yes |
OPTIONS | Discover server capabilities (used in CORS preflight) | No | Yes | Yes |
Idempotent means making the same request multiple times produces the same result. Safe means the method doesn’t change server state.
HTTP status codes
Status codes are three-digit numbers that tell the client the result of the request:
| Range | Category | Common examples |
|---|---|---|
| 1xx | Informational | 100 Continue, 101 Switching Protocols |
| 2xx | Success | 200 OK, 201 Created, 204 No Content |
| 3xx | Redirection | 301 Moved Permanently, 302 Found, 304 Not Modified |
| 4xx | Client error | 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found, 429 Too Many Requests |
| 5xx | Server error | 500 Internal Server Error, 502 Bad Gateway, 503 Service Unavailable, 504 Gateway Timeout |
The first digit defines the category. 4xx means the client made an error. 5xx means the server failed.
Key HTTP headers
Request headers
| Header | Purpose | Example |
|---|---|---|
Host | Target server domain | Host: api.example.com |
Authorization | Authentication credentials | Authorization: Bearer <token> |
Content-Type | Format of the request body | Content-Type: application/json |
Accept | Formats the client can handle | Accept: application/json |
Cache-Control | Caching directives | Cache-Control: no-cache |
User-Agent | Client software identifier | User-Agent: Mozilla/5.0 |
Response headers
| Header | Purpose | Example |
|---|---|---|
Content-Type | Format of the response body | Content-Type: text/html; charset=utf-8 |
Cache-Control | How long to cache the response | Cache-Control: max-age=3600 |
Location | Redirect target URL | Location: https://example.com/new |
Set-Cookie | Set a cookie on the client | Set-Cookie: session=abc; HttpOnly |
Strict-Transport-Security | Enforce HTTPS | Strict-Transport-Security: max-age=31536000 |
HTTP versions compared
| Feature | HTTP/1.1 | HTTP/2 | HTTP/3 |
|---|---|---|---|
| Year | 1997 | 2015 | 2022 |
| Transport | TCP | TCP | QUIC (UDP) |
| Multiplexing | No (one request per connection) | Yes (many requests per connection) | Yes |
| Header compression | No | Yes (HPACK) | Yes (QPACK) |
| Head-of-line blocking | Yes | Yes (at TCP level) | No |
| TLS required | No | In practice yes (browsers require it) | Yes (built in) |
| Connection setup | TCP handshake | TCP + TLS handshake | QUIC (1-RTT or 0-RTT) |
HTTP/1.1 opens a new TCP connection for each request (or reuses connections with keep-alive, but still serializes requests). HTTP/2 sends multiple requests simultaneously over one connection. HTTP/3 eliminates TCP head-of-line blocking by using QUIC over UDP — packet loss on one stream doesn’t stall others.
HTTP vs HTTPS
| HTTP | HTTPS | |
|---|---|---|
| Port | 80 | 443 |
| Encryption | None | TLS |
| Authentication | None | Server certificate |
| Data integrity | Not guaranteed | Guaranteed by TLS |
| SEO | Penalized by Google | Required for ranking |
| Browser indicator | ”Not secure” warning | Padlock icon |
HTTPS is HTTP with a TLS layer added. The TLS handshake happens before any HTTP data flows. All HTTP content — including headers, cookies, and request bodies — is encrypted in HTTPS.
Frequently asked questions
What is HTTP in simple terms? HTTP is the language browsers and web servers use to talk to each other. When you type a URL and press Enter, your browser sends an HTTP request asking for that page. The server sends back an HTTP response containing the HTML. HTTP defines the format of both messages.
What is the difference between HTTP and HTTPS? HTTPS is HTTP with TLS encryption. In HTTP, all data travels in plaintext — anyone between you and the server can read it. In HTTPS, TLS encrypts the connection so only the client and server can read the data. Modern browsers require HTTPS and warn users about HTTP sites.
What does HTTP stateless mean? HTTP stateless means each request is completely independent — the server doesn’t remember previous requests from the same client. Every request must contain all the information needed to process it. Applications maintain state (like login sessions) using cookies, tokens, or server-side sessions layered on top of HTTP.
What is the difference between GET and POST? GET retrieves data and should have no side effects — it’s safe and idempotent. GET parameters go in the URL. POST submits data to the server (creating or modifying resources) and has a request body. POST is not idempotent — calling it twice creates two resources.
What does a 404 error mean? A 404 Not Found error means the server received and understood the request, but could not find the requested resource. The resource may never have existed, may have been deleted, or the URL may be wrong. It’s a client error (4xx) because the client requested something that isn’t there.
What is HTTP/2 and why is it faster? HTTP/2 introduced multiplexing — sending multiple requests simultaneously over a single TCP connection. HTTP/1.1 sent requests one at a time per connection (or opened many parallel connections). HTTP/2 also compresses headers (HPACK) and allows servers to push resources proactively. The result is significantly fewer connection overhead and faster page loads.
What is HTTP/3? HTTP/3 replaces TCP with QUIC, a transport protocol built on UDP. QUIC integrates TLS 1.3 directly, reducing connection setup to 1-RTT (or 0-RTT for returning connections). It eliminates head-of-line blocking — in HTTP/2 over TCP, one lost packet stalls all streams; QUIC handles each stream independently. HTTP/3 is especially beneficial on mobile networks where packet loss is common.
What is an HTTP header? An HTTP header is a key-value pair sent in an HTTP request or response that provides metadata. Request headers tell the server about the client (Accept language, Authorization token, Content-Type of the body). Response headers tell the client about the response (Content-Type of the body, Cache-Control directives, security policies like HSTS).