67 entries · 6 sections
HTTP Status Codes Cheat Sheet
Every HTTP status code you are likely to send or receive, with what it actually means rather than its one-word name — plus a section on the pairs people confuse: 401 against 403, 301 against 308, 400 against 422, and 502 against 504.
1xx and 2xx — Informational and success
| Syntax | What it does |
|---|---|
100 Continue | The server has read the request headers and the client should go ahead and send the body. |
101 Switching Protocols | The server is switching protocols as asked. This is how a WebSocket handshake completes. |
102 Processing | WebDAV: the request is being worked on and the real response will follow. Now deprecated. |
103 Early Hints | Preliminary headers — usually Link: rel=preload — sent so the browser can start fetching assets before the real response. |
200 OK | The standard success response, with the result in the body. |
201 Created | A new resource now exists. Its URL belongs in the Location header. |
202 Accepted | Accepted for processing but not finished. The response for a queued or async job. |
203 Non-Authoritative Information | Success, but a proxy modified the payload on the way through. |
204 No Content | Success, with deliberately no body at all. Common for DELETE and for PUT. |
205 Reset Content | Success; the client should clear the form it just submitted. |
206 Partial Content | The body is the byte range the client asked for. Video seeking and resumable downloads rely on it. |
207 Multi-Status | WebDAV: the XML body carries a separate status for each sub-request. |
208 Already Reported | WebDAV: this member was already enumerated earlier in the same multi-status response. |
226 IM Used | The response is the result of instance manipulations, such as a delta encoding, applied to the resource. |
3xx — Redirection
| Syntax | What it does |
|---|---|
300 Multiple Choices | Several representations exist and the client should pick one. |
301 Moved Permanently | The resource has a new URL for good. Search engines pass ranking signals to the new address. |
302 Found | A temporary redirect. Historically ambiguous about whether the method is preserved, which is why 303 and 307 exist. |
303 See Other | Fetch a different URL with GET. The correct answer to a successful POST. |
304 Not Modified | The client's cached copy is still valid. No body is sent, which is the point. |
307 Temporary Redirect | Temporary, and the method and body must be preserved exactly. |
308 Permanent Redirect | Permanent, and the method and body must be preserved exactly. |
4xx — Client errors (400-412)
| Syntax | What it does |
|---|---|
400 Bad Request | The server could not parse or accept the request. The catch-all client error. |
401 Unauthorized | Authentication is missing or invalid. Despite the name it means unauthenticated, and it should carry WWW-Authenticate. |
402 Payment Required | Reserved by the specification; some APIs use it for billing and quota problems. |
403 Forbidden | Understood, authenticated — and still not allowed. |
404 Not Found | There is no resource at this URL, and the server will not say whether there ever was. |
405 Method Not Allowed | The URL exists but not for this method. The response must include an Allow header. |
406 Not Acceptable | Nothing the server can produce matches the client's Accept header. |
407 Proxy Authentication Required | Like 401, but it is the proxy that wants credentials. |
408 Request Timeout | The client took too long to send the request and the server gave up waiting. |
409 Conflict | The request clashes with the current state — a duplicate unique key, or an edit against a stale version. |
410 Gone | Deliberately removed and not coming back. A stronger, more honest statement than 404. |
411 Length Required | The request must include a Content-Length header. |
412 Precondition Failed | An If-Match or If-Unmodified-Since condition on the request was not met. |
4xx — Client errors (413-451)
| Syntax | What it does |
|---|---|
413 Content Too Large | The body is bigger than the server will accept. Older specifications called it Payload Too Large. |
414 URI Too Long | The URL exceeds what the server is willing to process. |
415 Unsupported Media Type | The Content-Type is one this endpoint does not handle. |
416 Range Not Satisfiable | The requested byte range lies outside the resource. |
417 Expectation Failed | The server cannot meet the requirement in the Expect header. |
418 I'm a teapot | A 1998 April Fools' joke that never left the registry. Do not use it in a real API. |
421 Misdirected Request | The request reached a server that cannot produce a response for that authority. |
422 Unprocessable Content | The syntax is fine but the content fails validation. Most APIs' validation error. |
423 Locked | WebDAV: the resource is locked. |
425 Too Early | The server refuses to risk processing a request that was replayed from TLS early data. |
426 Upgrade Required | The client must switch protocols — typically to TLS. |
428 Precondition Required | The server insists on a conditional request, to prevent lost updates. |
429 Too Many Requests | Rate limited. It should always carry a Retry-After header. |
431 Request Header Fields Too Large | The headers, or one individual header, are too big. |
451 Unavailable For Legal Reasons | Blocked by law — a takedown or a censorship order. |
5xx — Server errors
| Syntax | What it does |
|---|---|
500 Internal Server Error | Something broke and the server has nothing more specific to say. Usually an unhandled exception. |
501 Not Implemented | The server does not support this method for any resource. |
502 Bad Gateway | A proxy or load balancer got an invalid response from the server behind it. |
503 Service Unavailable | Down or overloaded, and expected to return. Pair it with Retry-After. |
504 Gateway Timeout | A proxy waited too long for the upstream server to answer. |
505 HTTP Version Not Supported | The server refuses to handle that version of the protocol. |
507 Insufficient Storage | WebDAV: not enough space to complete the request. |
508 Loop Detected | WebDAV: an infinite loop was found while processing the request. |
511 Network Authentication Required | A captive portal wants you to log in before it will let traffic through. |
Choosing between the confusing pairs
| Syntax | What it does |
|---|---|
200 or 201 | Return 201 only when a new resource was created, and include its URL in Location. Otherwise 200. |
301 or 308 | Both are permanent. 308 additionally guarantees that a POST is not silently turned into a GET. |
302, 303 or 307 | 303 forces GET, 307 preserves the method, 302 is ambiguous. Pick 303 or 307 and be explicit. |
401 or 403 | 401 means "I do not know who you are"; 403 means "I know, and the answer is still no". |
404 or 410 | 410 states the removal is permanent, which makes search engines drop the URL considerably faster. |
400 or 422 | 400 for a request the server could not parse; 422 for one it parsed fine but that fails your rules. |
429 and Retry-After | Always send it, in seconds or as an HTTP date. Without it, clients cannot back off politely. |
500, 502 or 504 | Your application threw, the proxy got garbage, or the proxy timed out. They point at different machines. |
503 for maintenance | Use 503 with Retry-After rather than a 200 page saying "we're down" — it protects your search rankings. |
Worth knowing
- 401 and 403 are not interchangeable. Send 401 when the request carried no credentials or bad ones, along with a WWW-Authenticate header telling the client how to authenticate; send 403 when the credentials were fine but the identity lacks permission. Some APIs deliberately return 404 instead of 403 so that unauthorised users cannot discover which resources exist.
- A redirect that changes the HTTP method is a real source of bugs. 301 and 302 were widely implemented as "turn POST into GET", which is why 307 and 308 were specified to forbid exactly that. If your redirect might be hit by a POST, use 307 or 308.
- Never return 200 with an error message in the body. Clients, proxies, caches and monitoring all key off the status line, so a 200 error is invisible to every layer between you and the caller — and it will be cached as a successful response.
Try a snippet instead of reading about it
Reference is faster when you can run the thing. Paste a snippet into AltF Code, the free in-browser editor — real syntax highlighting for HTML, CSS, JavaScript, Python, SQL, JSON and more, with HTML, CSS and JavaScript running live in the preview. No install and no sign-up.
Open the editorHTTP Status Codes — common questions
- What is the difference between 401 and 403?
- 401 Unauthorized actually means unauthenticated: the request had no credentials, or invalid ones, and the response should include a WWW-Authenticate header. 403 Forbidden means the server knows who you are and is refusing anyway — a permissions problem, not a login problem. Sending fresh credentials fixes a 401 and does nothing for a 403.
- Which redirect should I use, 301 or 302?
- 301 for a permanent move, 302 only for a genuinely temporary one. 301 is cached aggressively by browsers and transfers search ranking signals, which makes it very hard to undo — so if there is any chance you will move the URL back, use 302 or 307. When the method matters, prefer 308 and 307, which are the method-preserving versions of the two.
- When should I return 422 instead of 400?
- Use 400 when the request itself is malformed — broken JSON, a missing required parameter, a bad content type. Use 422 Unprocessable Content when the request parsed correctly but the values violate your business rules, such as an email that is already taken or an end date before a start date. It lets clients distinguish "you sent nonsense" from "your data is wrong".
- What does a 502 Bad Gateway actually mean?
- A proxy — nginx, a load balancer, a CDN — asked the application server for a response and got something invalid or nothing at all, usually because the application is not running, crashed, or is listening on a different port. It is distinct from 504, where the application was reachable but took too long to answer, and from 500, where the application itself returned an error.