HTTP, TLS & Web Performance

HTTP Status Codes Explained by Family

Read any HTTP status code by its first digit, learn the common ones and decide who has to act when something goes wrong.

Key takeaways

  • The first digit defines the family, and software that meets an unknown code treats it like the family's 00 member.
  • 4xx points at the request, while 5xx points at the server or something it depends on.
  • Redirect codes differ in whether the move is permanent and whether the method is preserved.
  • Retrying helps with temporary failures such as 429, 502, 503 and 504, as long as you slow down and the request is safe to repeat.
  • A site should return honest codes, because browsers, caches, monitors and search engines act on them.

Every HTTP response starts with a three-digit status code, and the first digit tells you the kind of answer. 1xx means "keep going", 2xx means success, 3xx means look elsewhere or use your copy, 4xx means something about the request was a problem and 5xx means the server side failed.

If you remember only the families, you can already tell whether to fix your request, wait and retry or contact whoever runs the site. The individual codes add detail.

The five families

Reading the first digit
2xx Success Request understood and accepted 200, 201, 204, 206 Nothing to fix 3xx Redirect Go elsewhere or reuse a copy 301, 302, 304, 307, 308 Client follows automatically 4xx Client error Problem with the request 400, 401, 403, 404, 429 Change something before retrying 5xx Server error Server side could not deliver 500, 502, 503, 504 Often temporary 2xx Success Request understood and accepted 200, 201, 204, 206 Nothing to fix 3xx Redirect Go elsewhere or reuse a copy 301, 302, 304, 307, 308 Client follows automatically 4xx Client error Problem with the request 400, 401, 403, 404, 429 Change something before retrying 5xx Server error Server side could not deliver 500, 502, 503, 504 Often temporary

The codes are defined mainly in RFC 9110, with a registry kept by IANA for additions from other documents. The text beside the number, such as "Not Found", is a human label that HTTP/2 and HTTP/3 do not even transmit.

1xx: informational

These are interim messages before the final answer, and you will seldom see them.

  • 100 Continue tells a client that asked permission with Expect: 100-continue to go ahead and send its body.
  • 101 Switching Protocols confirms a change of protocol, most often to a WebSocket.
  • 103 Early Hints lets a server suggest files to start loading while it is still preparing the real response.

2xx: success

  • 200 OK is the ordinary answer.
  • 201 Created means something new now exists, usually named in a Location header.
  • 202 Accepted means the work is queued but not finished.
  • 204 No Content is success with nothing to display.
  • 206 Partial Content answers a range request, used when resuming downloads or seeking in video.

Success only describes HTTP. A page can return 200 while showing "something went wrong" in its text. That misleads monitors and search engines.

3xx: redirection

Most of these carry a Location header with the new address.

Code Name Permanent? Method kept?
301 Moved Permanently Yes Not guaranteed
302 Found No Not guaranteed
303 See Other No Switches to GET
307 Temporary Redirect No Yes
308 Permanent Redirect Yes Yes

304 Not Modified is different: it sends no new location. It answers a conditional request to say your cached copy is still good. The full comparison of the others is in 301 vs. 302 vs. 307 vs. 308.

4xx: client errors

"Client" means the request, not necessarily the person. A broken link on someone's site produces a 4xx even though the visitor did nothing wrong.

  • 400 Bad Request: the server could not make sense of it, for instance malformed syntax. Oversized or corrupted cookies can trigger it.
  • 401 Unauthorized: valid authentication is missing.
  • 403 Forbidden: the server understood but refuses. See 403 vs. 401.
  • 404 Not Found: nothing is available at that address. Causes and fixes have their own guide.
  • 405 Method Not Allowed: wrong method for this resource.
  • 408 Request Timeout: the client took too long to send the request.
  • 409 Conflict: the request clashes with the current state, such as a duplicate or a competing edit.
  • 410 Gone: deliberately and lastingly removed.
  • 413 Content Too Large: the upload exceeds a limit.
  • 415 Unsupported Media Type: the body's format is not accepted.
  • 422 Unprocessable Content: well formed, but the values do not pass validation.
  • 429 Too Many Requests: rate limit reached; see 429 and rate limiting.
  • 451 Unavailable For Legal Reasons: withheld because of a legal demand.

5xx: server errors

  • 500 Internal Server Error: an unspecified failure, often a bug. See investigating a 500.
  • 501 Not Implemented: the server does not support what the method requires.
  • 502 Bad Gateway: a proxy got an invalid response from the server behind it.
  • 503 Service Unavailable: temporarily unable to serve, from overload or maintenance. See 503 done right.
  • 504 Gateway Timeout: a proxy gave up waiting for the server behind it.
  • 505 HTTP Version Not Supported: rare in practice.

Codes outside the standard

Some servers and content delivery networks invent their own numbers. nginx logs 499 when a client closes the connection before an answer is ready. Several networks use codes in the 520s for problems reaching a website's origin server. If you meet an unfamiliar number, check which product produced the page and read its documentation. The HTTP status reference is a quick way to look up the standard ones.

Where in the chain did the code come from?

A modern website is usually several layers: a content delivery network, a load balancer, a web server, an application and the services behind it. Any of them can write the status you receive.

That changes how you read an error. A 403 might come from the application's permission check, from a firewall in front of it that disliked the request or from a storage service where a file's access settings are wrong. A 503 might mean the whole application is down, or that one layer is deliberately shedding load.

Clues include the look of the error page, the Server or Via headers, vendor-specific request ID headers and whether the application's own logs mention the request at all. If they do not, something earlier in the chain answered. 502 and 504 errors are the clearest case of one layer reporting on another.

Retrying without making things worse

Automatic retries are helpful for brief faults and harmful during real overloads. Sensible rules for scripts and applications:

  • Retry 408, 429, 502, 503 and 504 after a pause. A 500 may be worth one more attempt if the operation is harmless to repeat.
  • Do not retry 400, 401, 403, 404 or 422 unchanged. The answer will be the same.
  • Honor Retry-After when the server sends it, either a number of seconds or a date.
  • Increase the delay between attempts, add a little randomness and stop after a fixed number.
  • Check that the method is safe to repeat. Sending a second order because the first timed out is worse than reporting a failure.

Codes and search engines

Crawlers treat the families much as browsers do. A 200 invites indexing. A permanent redirect passes the visit to the new address and signals that it should replace the old one. A 404 or 410 says the page is gone, and it will eventually drop out of results. Persistent 5xx and 429 answers lead crawlers to slow down, and if they continue long enough, pages can be removed too.

This is why a maintenance notice served with 200 is risky: the crawler may take the notice to be the new content of every page. Each search engine documents its own handling, so check there for details.

Who should act?

What to do with an error response
Is it 401 or 403? YES Sign in, or confirm you have permission. 1 NO Is it 404 or 410? YES Check the address, then search the site. 2 NO Is it 429 or 503? YES Wait, honoring Retry-After, then try again. 3 NO Is it another 5xx? YES Retry once later, then report it to the site. 4 NO Fix the request Inspect the address, data, headers and cookies you are sending. Is it 401 or 403? 1 IF YES Sign in, or confirm you have permission. NO Is it 404 or 410? 2 IF YES Check the address, then search the site. NO Is it 429 or 503? 3 IF YES Wait, honoring Retry-After, then try again. NO Is it another 5xx? 4 IF YES Retry once later, then report it to the site. NO Fix the request Inspect the address, data, headers and cookies you are sending.

As a visitor, useful steps for 4xx include reloading, retyping the address, clearing cookies for that one site and trying a private window. For 5xx, your settings are rarely at fault. If many people see the same errors, check the operator's status page; reading status pages helps you interpret it.

Seeing the real code

Browser developer tools show the code for every request in the Network tab. From a terminal:

curl -s -o /dev/null -w "%{http_code}\n" https://www.example.com/missing

On Windows use curl.exe and replace /dev/null with NUL. Add -L to follow redirects and -i to see the headers that explain them.

An error page you see may not reflect an HTTP code at all. Messages such as "connection refused" or "name not resolved" mean no HTTP response arrived. Those are covered in connection errors and what each means.

Returning good codes from your own site

  1. Match the code to the truth. Missing pages should return 404, not a 200 page that says "not found". Search engines call the latter a soft 404.
  2. Do not redirect every error to the home page. Visitors lose their place and tools lose the signal.
  3. Use temporary codes for temporary states. During maintenance, 503 with Retry-After tells crawlers to come back.
  4. Keep details private. Error pages should not expose stack traces, file paths or database messages.
  5. Include a reference ID on server errors, and log it, so a report can be matched to a log line.

Watching codes over time

Server logs record a status for every request. A sudden rise in 5xx suggests a deployment or dependency problem. A rise in 404s may mean a broken link, a moved section or a scanner probing for software you do not run. A steady stream of 401 or 403 against a login page may deserve a security look. Reading server logs shows how to count them, and uptime monitoring can alert you when a key page stops answering with the code you expect.

Percentages help more than raw counts. A hundred errors means something different at a thousand requests than at ten million.

A quick triage example

Say a visitor reports that "the site is giving errors". Ask for the address, the time and the exact message. Then find that request in your logs.

If the log shows 404 for an address with a stray punctuation mark on the end, someone's link was copied badly, and a redirect may be worth adding. If it shows 403 only for uploads, look at firewall rules and file permissions. If it shows a cluster of 504 responses on the report page during business hours, something behind the proxy is too slow under load. If the log has no entry at all, the request never reached that server, so check DNS, any content delivery network and the visitor's own connection.

The code does not solve the problem, but it tells you which of those four investigations to start.

Written for 4Internet with AI writing tools and not reviewed line by line by a person. Check anything you rely on with the maker, provider or standard concerned. Report an error.

Keep reading

All 45 articles in HTTP, TLS & Web Performance →

Latest news on this topic