All cheat sheets

HTTP Status Codes Cheat Sheet

HTTP response status codes: 1xx–5xx classes, common codes, and when to use them.

Web & Network
http
status-codes
web

HTTP status codes summarize the result of a request in three digits. The first digit identifies the class; the remaining digits provide a more specific meaning defined by the HTTP specification or an application convention.

Status classes

The class tells a client how broadly to interpret the response. A client should generally handle unknown codes according to their class and preserve response headers and body when useful.

Table
ClassNameGeneral meaning
1xxInformationalRequest received; continue or provide interim information.
2xxSuccessRequest was successfully received and processed.
3xxRedirectionFurther action or another location may be needed.
4xxClient errorThe request cannot be fulfilled as sent.
5xxServer errorThe server failed to fulfill an apparently valid request.

1xx and 2xx

Informational responses are usually handled by protocol-aware clients. Success codes distinguish returned content, resource creation, and an intentionally empty response.

Table
CodeMeaningTypical use
100ContinueClient may send the request body.
101Switching ProtocolsProtocol upgrade accepted.
200OKSuccessful request with a representation or result.
201CreatedResource created; Location may identify it.
202AcceptedAccepted for asynchronous processing.
204No ContentSuccessful request with no response body.
http
HTTP/1.1 201 Created
Location: /users/42
Content-Type: application/json

{"id":42,"name":"Ada"}

3xx redirects and caching

Redirect codes tell a client to use another target or indicate that a cached representation remains valid. 301 and 308 are permanent; 302 and 307 are temporary. The 307 and 308 forms preserve the request method and body during the redirect.

Table
CodeMeaning
301Permanently moved; clients may rewrite future requests.
302Temporary redirect; historical clients may change method to GET.
303See another resource, commonly after POST with a GET.
304Not modified; use a valid cached representation.
307Temporary redirect preserving method and body.
308Permanent redirect preserving method and body.

4xx client errors

A 4xx response means the server considers something about the request invalid, unauthorized, forbidden, missing, conflicting, or rate-limited. APIs should return a useful body when clients can correct the request.

Table
CodeMeaning
400Bad Request: malformed syntax or invalid request framing.
401Unauthorized: authentication is required or invalid.
403Forbidden: identity is known or understood, but access is refused.
404Not Found: target resource does not exist or is intentionally hidden.
405Method Not Allowed: method is unsupported for the target.
409Conflict with the current resource state.
422Content understood but semantically invalid.
429Too Many Requests: rate limit exceeded.

401 concerns authentication; 403 concerns authorization. A 401 response commonly includes a WWW-Authenticate challenge, while 403 does not require the client to authenticate differently.

5xx server errors

5xx responses indicate a failure while processing a request the server could not complete. Gateways and proxies may generate some of these codes on behalf of an upstream service.

Table
CodeMeaning
500Unexpected condition in the server.
501Server does not support the requested functionality.
502Gateway received an invalid upstream response.
503Service temporarily unavailable, often overloaded or under maintenance.
504Gateway timed out waiting for an upstream response.
http
HTTP/1.1 503 Service Unavailable
Retry-After: 120
Content-Type: application/json

{"error":"temporarily unavailable"}

Client handling patterns

Treat status classes separately and respect headers such as Location, Retry-After, and caching validators. Retrying a request is safe only when the operation and server contract make it safe; use backoff for transient failures.

javascript
if (response.status === 429 || response.status >= 500) {
  const retryAfter = response.headers.get("Retry-After");
  // Apply bounded backoff according to the API contract.
} else if (!response.ok) {
  throw new Error(`Request failed: ${response.status}`);
}

References