15 min read
HTTP status codes list: the most common ones
In one sentence: A status code is the three-digit number the server uses to sum up what happened to a request. The first digit already says almost everything: 2xx went well, 3xx is somewhere else, 4xx is the fault of whoever asks and 5xx is the server's.
What you will learn
- Read the first digit of a code and know whose problem it is, and whether repeating the request is any use.
- Choose the right code among the twenty most used ones, and tell 401 from 403.
- Follow a redirect with its Location header, and choose between 301, 302, 307 and 308.
- Explain why a 200 with an error inside is a design mistake.
Before you start, read: 02-methods.md phase-1/03-pipes-and-redirection.md
The problem
Section titled “The problem”Imagine a customer of Ana and Luis’s shop orders a hoodie from the phone app. The app shows “Order placed!”, but the order never arrives: there was no stock. The shop’s APIAPI stands for Application Programming Interface.The way a program offers its services to other programs, that is, what you can ask it for and how it answers. The frontend talks to the backend through an API.Go to definition had answered 200 OK, with a text that said {"error": "out of stock"}.
The app didn’t read the text: it saw a 200 and took the order as done. Programs decide by the Status codeA three-digit number at the start of every HTTP response that sums up what happened. 200 means “all good,” 404 “that doesn’t exist” and 400 “your request is malformed.”Go to definition, not by what it says underneath. So do the browser, Google, caches and your own alerts.
In Phase 0 you saw 200, 400 and 404. In everyday use there are about twenty: this lesson tells you what each one promises.
The analogy
Section titled “The analogy”The analogy
Imagine the counter of a government office. You hand in a form and the clerk gives it back with a stamp in one of four colors:
- Green, “processed”: everything went well.
- Blue, “that’s done at counter 5”: it’s not an error; you go to the other counter.
- Orange, “a signature is missing”: the problem is yours. If you hand in the same thing, you’ll get the same stamp.
- Red, “the system is down”: the problem is the office’s. If you come back later with the same paper, it may work.
The color is the first digit of the code, and the text of the stamp, the rest.
Where the analogy breaks down
- The clerk explains the stamp in words. A program only reads the number: the phrase that comes with the code is decoration, and in HTTP/2 it doesn’t even travel.
- When they send you to counter 5, you walk there yourself. With a redirect, the browser goes on its own, without asking you.
- The clerk tells you why they won’t serve you. A server sometimes has to keep it quiet: you’ll see this with the
404that hides things.
How it really works
Section titled “How it really works”The first digit says whose problem it is
Section titled “The first digit says whose problem it is”In lesson 3 of Phase 1 you counted the 200, 301, 404 and 500 codes in the practice log. The first digit puts each code in one of five families:
| Family | What it says | Whose problem is it? | Does repeating it help? |
|---|---|---|---|
1xx |
An early notice, which you’ll almost never see | Nobody’s | No need |
2xx |
Everything went well | Nobody’s | No need |
3xx |
What you’re looking for is somewhere else, or you already have it | Nobody’s: there’s one more step | The client takes that step on its own |
4xx |
ClientThe program that starts the conversation by asking another program, the server, for something. Your browser is a client.Go to definition error | Whoever asks | No: the request has to change (or, with a 429, you have to wait) |
5xx |
ServerA program that waits for requests and answers them. By extension, the computer it runs on is also called a server.Go to definition error | The server’s | Maybe, later |
The last column is the one that matters most. With a 4xx, repeating the request will give the same error. With a 5xx, trying again later may work, and that’s why many programs retry on their own (which is why it matters whether the method is IdempotentSaid of an operation that leaves things in the same state whether you do it once or ten times. In HTTP, GET, PUT and DELETE are idempotent and POST isn’t, so repeating a POST can create two orders.Go to definition, as you saw in “Methods”).
The family matters so much that the standard puts it in writing: a client that gets a code it doesn’t know, like a 499, treats it as the x00 of its family, here a 400.
The phrase is for humans
Section titled “The phrase is for humans”After the number comes a phrase, like Not Found in 404 Not Found. It’s for people, and no program should rely on it. nginx uses its own: 302 Moved Temporarily, where the standard says 302 Found. And in HTTP/2HTTP stands for HyperText Transfer Protocol.The 2015 version of HTTP. It says the same as HTTP/1.1, but cut into pieces and in a format made for machines, not text, and it carries many requests at once over a single TCP connection. Browsers only use it with HTTPS.Go to definition the phrase no longer travels: Cloudflare answers HTTP/2 404, just the number.
The codes that matter
Section titled “The codes that matter”This is for looking up, not for memorizing. The examples are from the shop:
| Code | What it says | An example |
|---|---|---|
200 OK |
Here’s what you asked for | GET /products returns the list |
201 Created |
I’ve created something new | POST /api/orders creates an order |
204 No Content |
Done, and there’s nothing to tell | You remove something from the cart: the response has no Body (of a request or response)The data an HTTP message carries after the blank line that ends the headers, such as the fields of a form, some JSON or an image. The Content-Type header says what format it’s in, and Content-Length how many bytes it takes up.Go to definition |
301, 302, 307 and 308 |
It’s at another address | /offers leads to /products (redirects) |
304 Not Modified |
What you already have stored is still good | You’ll see it in “Caching” |
400 Bad Request |
Your request is badly formed | The body claims to be JSONJSON stands for JavaScript Object Notation.A format for writing data as text, with braces, quotes and colons: {"product":"mug","quantity":2}. People can read it, and so can almost any programming language, and it’s the most common format for the data that travels between a frontend and a backend.Go to definition and it isn’t |
401 Unauthorized |
I don’t know who you are | You ask for your orders without having logged in |
403 Forbidden |
I know who you are, and you can’t | A customer tries to get into the admin panel |
404 Not Found |
That doesn’t exist (or I won’t tell you) | /products/999 |
405 Method Not Allowed |
It exists, but not with that method | POST /products (“Methods”) |
409 Conflict |
It clashes with how things are | You sign up with an email that already has an account |
422 Unprocessable Content |
It’s understood, but the data isn’t valid | An order for -3 hoodies |
429 Too Many Requests |
Too many requests: wait | A hundred passwords a minute (Phase 6) |
500 Internal Server Error |
I failed | A bug in the shop’s program |
502 Bad Gateway |
The one behind me answered badly | The shop’s program has crashed |
503 Service Unavailable |
I can’t serve you right now | The shop is under maintenance |
504 Gateway Timeout |
The one behind me is taking too long | The shop’s program is stuck |
Two pairs confuse almost everyone:
400vs422: with a400, the server couldn’t even read the request. With a422, it read it, and what it asks for doesn’t make sense.502and504vs500: on many websites, in front of the program that answers there’s another server, like nginx or Cloudflare, that passes the requests on to it.500says “I failed”;502and504, “the one behind me failed” (you’ll set it up in Phase 8).
401 or 403: “I don’t know who you are” or “you can’t”
Section titled “401 or 403: “I don’t know who you are” or “you can’t””GitHub’s API asks you to identify yourself before telling you who you are:
curl -si https://api.github.com/userHTTP/2 401content-type: application/json; charset=utf-8server: github.com…
{ "message": "Requires authentication", "documentation_url": "https://docs.github.com/rest", "status": "401"}Requires authentication: you have to identify yourself first. That’s the difference:
401: I don’t know who you are. You haven’t logged in, or your identification has expired. If you identify yourself, it may work.403: I know who you are, and you can’t. You’ve logged in, but your account doesn’t have permission. Identifying yourself again changes nothing.
It’s like a concert: without a wristband you don’t get past the entrance (401), and with a regular wristband you don’t get into the VIP area (403). The name of the 401, Unauthorized, is misleading: it should be “Unauthenticated.” You’ll see it in Phase 6.
The 404 also hides things
Section titled “The 404 also hides things”A 403 says “that exists, but it’s not for you,” and sometimes that’s already too much. If a customer asks for /api/orders/1044, someone else’s order, a 403 confirms that order 1044 exists, and they can try 1045. A 404 tells them nothing.
GitHub does this with private repositories: if you don’t have access, it answers 404 and not 403, and its documentation explains it’s so as not to confirm they exist. If knowing that something exists already gives information away, answer 404.
The 200 with an error inside
Section titled “The 200 with an error inside”This is the shop’s response from “The problem”:
HTTP/1.1 200 OKContent-Type: application/json
{"error": "out of stock"}The body says something failed, and the code, that everything is fine. The code wins:
- The phone app takes the order as done.
- Your alerts don’t go off. In Phase 1 you found the failed payments by counting the
500codes in the log. With200on everything, they’d be invisible. - A CacheA saved copy of an answer, so it doesn’t have to be fetched again. It saves time, at the cost of the copy possibly being stale until it expires.Go to definition can store that response as a good one and hand it out.
- Google can keep in its index a page that only says “not found.” Its documentation calls it a soft 404.
The right thing is a code that tells the truth and a body that gives the details: 409 Conflict with {"error": "out of stock"}.
The code and the Location header: redirects
Section titled “The code and the Location header: redirects”Ask for this course’s home page over http://, without the s:
curl -sI http://backenddesdecero.comHTTP/1.1 301 Moved PermanentlyDate: Mon, 12 Oct 2026 18:35:32 GMTContent-Type: text/html; charset=UTF-8Connection: keep-aliveLocation: https://backenddesdecero.com/…Server: cloudflare…We’ve cut some HeaderInformation a protocol puts in front of its data to do its job. In HTTP they are text lines of the form “Name: value”, such as Host or Content-Type; in TCP or IP they are numbers in fixed positions, such as ports or addresses.Go to definition. The server doesn’t send the page, but a 301 and a Location header with the right address. That’s a RedirectAn HTTP response that says “what you’re looking for is at another address.” It carries a code starting with 3, such as 301, and the Location header with the new address. The browser requests it on its own, without you doing anything.Go to definition: a 3xx code plus Location. The browser, or curl -L, makes a new request to that address on its own.
Location can carry a full address, like this one, or just a path, like /en/phase-0/, which the client completes with the site it’s already on. One redirect can lead to another, and each hop costs a round trip (“From URL to page”):
- backenddesdecero.com → curl -L301
Location: https://backenddesdecero.com/en/phase-0 - backenddesdecero.com → curl -L307
location: /en/phase-0/ - backenddesdecero.com → curl -L200 and the page
There are four redirects in daily use, and you choose with two questions:
| For good | For now | |
|---|---|---|
May turn a POST into a GET |
301 Moved Permanently |
302 Found |
| Keeps the method and the body | 308 Permanent Redirect |
307 Temporary Redirect |
For good or for now? A 301 tells Google to use the new address in its results, and browsers can cache it and not ask again. A 302 says the opposite: the usual address is still the right one.
Can the method change? Years ago, browsers that followed a 301 or a 302 after sending a form changed the POST into a GET, and the data was lost. The standard ended up accepting it, and created 307 and 308 for when that mustn’t happen. With a GET, the method of almost every page, both rows work the same.
Try it
Section titled “Try it”The goal: see which code each server answers with, find a broken link in the practice log and change one of the shop’s redirects on your VM.
This site’s codes
Section titled “This site’s codes”In your computer’s terminal. The outputs are from a Mac, on October 13, 2026.
1. Three responses, three families
curl -s -o /dev/null -w '%{http_code}\n' https://backenddesdecero.com/en/phase-0/curl -s -o /dev/null -w '%{http_code}\n' https://backenddesdecero.com/en/phase-0curl -s -o /dev/null -w '%{http_code}\n' https://backenddesdecero.com/en/phase-0/does-not-existWhat you will see:
200307404As in “Methods”, -o /dev/null throws the body away and -w writes only the code. With the trailing slash, the page; without it, a redirect; with a made-up name, a 404.
If you get 000, curl couldn’t connect: check your connection.
2. Follow the chain of redirects
curl -sIL http://backenddesdecero.com/en/phase-0 | grep -i '^http\|^location'What you will see:
HTTP/1.1 301 Moved PermanentlyLocation: https://backenddesdecero.com/en/phase-0HTTP/2 307location: /en/phase-0/HTTP/2 200-L makes curl follow redirects, like the browser, and -I asks only for the headers. grep -i keeps the lines that start with http or with location, ignoring case; \| means “or”.
It’s the chain in the diagram. Notice that the first response comes over HTTP/1.1, with a phrase, and the others over HTTP/2, without one.
What the practice log tells you
Section titled “What the practice log tells you”Now, the Phase 1 practice log, in ~/backend-course/phase-1. If you don’t have it, download it there with curl -O https://backenddesdecero.com/practicas/access.log. It’s the same for everyone, so your numbers will be these; on Linux and WSL, uniq -c puts more spaces in front.
3. Count by family
cd ~/backend-course/phase-1cut -d' ' -f9 access.log | cut -c1 | sort | uniq -cWhat you will see:
865 219 364 426 5The first cut keeps the code, as in Phase 1, and the second, with -c1, its first character: the family. Of the day’s 90 errors, 64 were the fault of whoever was asking and 26, of the server.
4. Which pages have moved?
grep '" 301 ' access.log | cut -d' ' -f7 | sort | uniq -cWhat you will see:
8 /about-us11 /shopThe 19 redirects come from two old addresses. The log doesn’t keep the Location header, so it doesn’t say where they led.
5. Who links to a product that doesn't exist?
grep '" 404 ' access.log | cut -d' ' -f7 | sort | uniq -c | sort -rn | head -3grep '/products/57 ' access.log | cut -d'"' -f4 | sort | uniq -cWhat you will see:
9 /products/57 5 /prodcuts 4 /contact 5 - 1 https://example.com/about 1 https://example.com/blog 1 https://example.com/products 1 https://example.com/products/20The first command counts which paths give 404: the top one, /products/57. The second splits on the quotes and keeps the fourth piece, the page where the clicked link was. A - means there was no link: the visitor typed the address.
Four visits come from pages of the site itself. Product 57 was deleted, but the links are still there. They have to be removed and, if another product replaces it, /products/57 should redirect to it with a 301.
A redirect in the shop
Section titled “A redirect in the shop”The rest is done on your VM (multipass shell course), with the shop you installed in the introduction. If you don’t have a VM, read the outputs: they’re from an Ubuntu 24.04 with nginx 1.24.0.
6. The /offers redirect
curl -sI localhost:8080/offersWhat you will see:
HTTP/1.1 301 Moved PermanentlyServer: nginx/1.24.0 (Ubuntu)Date: Tue, 13 Oct 2026 07:59:57 GMTContent-Type: text/htmlContent-Length: 178Location: http://localhost:8080/productsConnection: keep-aliveThe configuration says return 301 /products;, just the path, and nginx completes it with the name and the port you called. Your date will be different. If you get Couldn't connect to server, nginx isn’t listening on 8080: go over the introduction again.
7. The shop under maintenance
curl -si localhost:8080/maintenanceWhat you will see:
HTTP/1.1 503 Service Temporarily UnavailableServer: nginx/1.24.0 (Ubuntu)Date: Tue, 13 Oct 2026 07:59:57 GMTContent-Type: text/html; charset=utf-8Content-Length: 206Connection: keep-aliveRetry-After: 120
<html><head><title>503 Service Temporarily Unavailable</title></head><body><center><h1>503 Service Temporarily Unavailable</h1></center><hr><center>nginx/1.24.0 (Ubuntu)</center></body></html>A 503 with Retry-After: 120: “I can’t serve you, come back in 120 seconds.” That’s the right answer for maintenance: Google understands it’s temporary. With a 200, it could keep the “under maintenance” page in its index.
Now, the change. Ana wants /offers to lead to the products only during the fall campaign, and afterward it will have its own page again. With a 301, browsers and Google would write /offers off: you need a temporary redirect.
Open the configuration with sudo nano /etc/nginx/sites-available/shop, as in “Methods”. Find the line return 301 /products; with Ctrl + W, change 301 to 302, save with Ctrl + O and Enter, and exit with Ctrl + X.
8. Check and reload
sudo nginx -t && sudo systemctl reload nginxWhat you will see:
nginx: the configuration file /etc/nginx/nginx.conf syntax is oknginx: configuration file /etc/nginx/nginx.conf test is successfulnginx -t checks the configuration, and && only reloads if it’s fine. If you get test failed, nginx tells you which line has the typo.
9. Ask for /offers again
curl -sI localhost:8080/offers | head -1What you will see:
HTTP/1.1 302 Moved TemporarilyNow the redirect is temporary, with nginx’s own phrase. If you still get 301, check that you saved the file and repeat step 8.
To undo it, put 301 back and repeat step 8.
Challenge: in the end, the fall campaign is canceled: /offers is never coming back, and no other page replaces it. Which code would you use? Change it in the shop and check it.Show answer
A 410 Gone, “it’s gone for good,” or a 404: there’s nowhere to redirect to. The line ends up like this, with no path:
return 410;After sudo nginx -t && sudo systemctl reload nginx, curl -sI localhost:8080/offers | head -1 answers HTTP/1.1 410 Gone. If nginx -t fails, check that the line ends in a semicolon.
When you’re done, put return 301 /products; back and reload.
You have already seen it
Section titled “You have already seen it”- The “Error 404” pages of any website, and Cloudflare’s with an “Error 502” or “Error 504”: the server in front is telling you that the one behind didn’t answer properly.
- In DevToolsThe developer tools that come with browsers such as Chrome or Firefox, opened with F12. Their Network tab shows every request the page makes, with its response and headers; the Console, the page’s errors; and Application (Storage, in Firefox), what the site stores in your browser, such as cookies.Go to definition, open the Network tab and go to
https://backenddesdecero.com/en/phase-0, without the trailing slash. In the Status column you’ll see two rows:phase-0with a307andphase-0/with a200. How to open DevTools is in the introduction.
And if you code:
fetchfollows redirects on its own, andresponse.redirectedtells you whether there was one.response.okistruewith any code between200and299, including a200that carries an error inside.- In Next.js, a redirect with
permanent: trueanswers308, and without it,307: Next.js picks the ones that keep the method.
Common mistakes
Section titled “Common mistakes”- Using
301for something temporary. Browsers can cache it, and if you undo it later, some visitors will keep going to the new address without asking. If in doubt, start with302or307. - Answering
401to someone who has already logged in and doesn’t have permission. Many apps, on a401, send you to the login screen: the user logs in again and gets another401, in a loop. The right answer is403. - Giving a
500for a client error. If someone sends broken JSON and your server fails while reading it, your alerts go off for someone else’s error, and the client thinks retrying may help. Check what arrives and answer400or422. - A redirect that comes back to itself. If
/aleads to/band/bto/a, Chrome gives up withERR_TOO_MANY_REDIRECTS, andcurl -L, after 50 hops, withcurl: (47) Maximum (50) redirects followed. Follow the chain withcurl -sIL, as in exercise 2.
Summary
Section titled “Summary”- The first digit says whose problem it is:
4xxis the fault of whoever asks (repeating doesn’t help) and5xxof the server (it may help later). - Programs read the number, not the phrase or the body: a
200with an error inside fools apps, alerts, caches and Google. 401is “I don’t know who you are” and403, “you can’t.” If confirming that something exists already gives information away, the answer is404.- A redirect is a
3xxwithLocation:301and308for good,302and307for now. - In Phase 3 you’ll write your own server, and you’ll choose the code of each response.
Did you get it?
Section titled “Did you get it?”To review:
Further reading
Section titled “Further reading”- HTTP response status codes, on MDN: the full list, with one page per code.
- RFC 9110, section 15: what the standard says about each code.
- How HTTP status codes affect Google’s crawlers: what Google does with each family and with soft 404s.