Skip to main content

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

SyntaxWhat it does
100 ContinueThe server has read the request headers and the client should go ahead and send the body.
101 Switching ProtocolsThe server is switching protocols as asked. This is how a WebSocket handshake completes.
102 ProcessingWebDAV: the request is being worked on and the real response will follow. Now deprecated.
103 Early HintsPreliminary headers — usually Link: rel=preload — sent so the browser can start fetching assets before the real response.
200 OKThe standard success response, with the result in the body.
201 CreatedA new resource now exists. Its URL belongs in the Location header.
202 AcceptedAccepted for processing but not finished. The response for a queued or async job.
203 Non-Authoritative InformationSuccess, but a proxy modified the payload on the way through.
204 No ContentSuccess, with deliberately no body at all. Common for DELETE and for PUT.
205 Reset ContentSuccess; the client should clear the form it just submitted.
206 Partial ContentThe body is the byte range the client asked for. Video seeking and resumable downloads rely on it.
207 Multi-StatusWebDAV: the XML body carries a separate status for each sub-request.
208 Already ReportedWebDAV: this member was already enumerated earlier in the same multi-status response.
226 IM UsedThe response is the result of instance manipulations, such as a delta encoding, applied to the resource.

3xx — Redirection

SyntaxWhat it does
300 Multiple ChoicesSeveral representations exist and the client should pick one.
301 Moved PermanentlyThe resource has a new URL for good. Search engines pass ranking signals to the new address.
302 FoundA temporary redirect. Historically ambiguous about whether the method is preserved, which is why 303 and 307 exist.
303 See OtherFetch a different URL with GET. The correct answer to a successful POST.
304 Not ModifiedThe client's cached copy is still valid. No body is sent, which is the point.
307 Temporary RedirectTemporary, and the method and body must be preserved exactly.
308 Permanent RedirectPermanent, and the method and body must be preserved exactly.

4xx — Client errors (400-412)

SyntaxWhat it does
400 Bad RequestThe server could not parse or accept the request. The catch-all client error.
401 UnauthorizedAuthentication is missing or invalid. Despite the name it means unauthenticated, and it should carry WWW-Authenticate.
402 Payment RequiredReserved by the specification; some APIs use it for billing and quota problems.
403 ForbiddenUnderstood, authenticated — and still not allowed.
404 Not FoundThere is no resource at this URL, and the server will not say whether there ever was.
405 Method Not AllowedThe URL exists but not for this method. The response must include an Allow header.
406 Not AcceptableNothing the server can produce matches the client's Accept header.
407 Proxy Authentication RequiredLike 401, but it is the proxy that wants credentials.
408 Request TimeoutThe client took too long to send the request and the server gave up waiting.
409 ConflictThe request clashes with the current state — a duplicate unique key, or an edit against a stale version.
410 GoneDeliberately removed and not coming back. A stronger, more honest statement than 404.
411 Length RequiredThe request must include a Content-Length header.
412 Precondition FailedAn If-Match or If-Unmodified-Since condition on the request was not met.

4xx — Client errors (413-451)

SyntaxWhat it does
413 Content Too LargeThe body is bigger than the server will accept. Older specifications called it Payload Too Large.
414 URI Too LongThe URL exceeds what the server is willing to process.
415 Unsupported Media TypeThe Content-Type is one this endpoint does not handle.
416 Range Not SatisfiableThe requested byte range lies outside the resource.
417 Expectation FailedThe server cannot meet the requirement in the Expect header.
418 I'm a teapotA 1998 April Fools' joke that never left the registry. Do not use it in a real API.
421 Misdirected RequestThe request reached a server that cannot produce a response for that authority.
422 Unprocessable ContentThe syntax is fine but the content fails validation. Most APIs' validation error.
423 LockedWebDAV: the resource is locked.
425 Too EarlyThe server refuses to risk processing a request that was replayed from TLS early data.
426 Upgrade RequiredThe client must switch protocols — typically to TLS.
428 Precondition RequiredThe server insists on a conditional request, to prevent lost updates.
429 Too Many RequestsRate limited. It should always carry a Retry-After header.
431 Request Header Fields Too LargeThe headers, or one individual header, are too big.
451 Unavailable For Legal ReasonsBlocked by law — a takedown or a censorship order.

5xx — Server errors

SyntaxWhat it does
500 Internal Server ErrorSomething broke and the server has nothing more specific to say. Usually an unhandled exception.
501 Not ImplementedThe server does not support this method for any resource.
502 Bad GatewayA proxy or load balancer got an invalid response from the server behind it.
503 Service UnavailableDown or overloaded, and expected to return. Pair it with Retry-After.
504 Gateway TimeoutA proxy waited too long for the upstream server to answer.
505 HTTP Version Not SupportedThe server refuses to handle that version of the protocol.
507 Insufficient StorageWebDAV: not enough space to complete the request.
508 Loop DetectedWebDAV: an infinite loop was found while processing the request.
511 Network Authentication RequiredA captive portal wants you to log in before it will let traffic through.

Choosing between the confusing pairs

SyntaxWhat it does
200 or 201Return 201 only when a new resource was created, and include its URL in Location. Otherwise 200.
301 or 308Both are permanent. 308 additionally guarantees that a POST is not silently turned into a GET.
302, 303 or 307303 forces GET, 307 preserves the method, 302 is ambiguous. Pick 303 or 307 and be explicit.
401 or 403401 means "I do not know who you are"; 403 means "I know, and the answer is still no".
404 or 410410 states the removal is permanent, which makes search engines drop the URL considerably faster.
400 or 422400 for a request the server could not parse; 422 for one it parsed fine but that fails your rules.
429 and Retry-AfterAlways send it, in seconds or as an HTTP date. Without it, clients cannot back off politely.
500, 502 or 504Your application threw, the proxy got garbage, or the proxy timed out. They point at different machines.
503 for maintenanceUse 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 editor

HTTP 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.