HTTP Status Codes Reference

CodeReasonMeaning & Usage
100 Continue Server received request headers; client should proceed to send the body.
101 Switching Protocols Server is switching protocols as requested (e.g. WebSocket upgrade).
200 OK Request succeeded.
201 Created Request succeeded and a new resource was created.
204 No Content Request succeeded; response has no body (common for DELETE/PUT).
206 Partial Content Server is delivering only part of the resource due to a Range header.
301 Moved Permanently Resource permanently moved to the URL in the Location header.
302 Found Temporary redirect; browsers may switch POST to GET.
304 Not Modified Cached version is still valid (If-None-Match / If-Modified-Since).
307 Temporary Redirect Temporary redirect preserving the original HTTP method.
308 Permanent Redirect Permanent redirect preserving the original HTTP method.
400 Bad Request Malformed syntax or invalid request parameters.
401 Unauthorized Authentication is required or credentials are invalid.
403 Forbidden Authenticated or not, the client lacks permission for this resource.
404 Not Found The requested resource does not exist.
405 Method Not Allowed HTTP method is not supported for this endpoint.
409 Conflict Request conflicts with current resource state (e.g. duplicate key).
413 Payload Too Large Request body exceeds server limit (e.g. nginx client_max_body_size).
422 Unprocessable Content Syntax is valid (e.g. JSON), but semantic/validation rules failed.
429 Too Many Requests Rate limit exceeded; check Retry-After header.
500 Internal Server Error Unexpected server-side error.
502 Bad Gateway Reverse proxy/gateway received an invalid response from upstream.
503 Service Unavailable Server is overloaded or down for maintenance.
504 Gateway Timeout Upstream server did not respond in time.

Understanding HTTP Status Code Classes

HTTP response status codes are three-digit numbers grouped into five classes by their first digit. Knowing which class a response belongs to immediately tells you whether a request succeeded, needs redirection, failed due to client input, or hit a server-side failure.

  • 1xx (Informational): The request was received and the connection is continuing (e.g. 101 Switching Protocols for WebSockets).
  • 2xx (Success): The request was successfully received, understood, and accepted (200 OK, 201 Created, 204 No Content).
  • 3xx (Redirection): Further action is required by the client, usually following a Location header (301 permanent, 302 temporary, 304 Not Modified for cache validation).
  • 4xx (Client Error): Something in the request is invalid or unauthorized (400 syntax, 401 unauthenticated, 403 forbidden, 404 not found, 422 validation error, 429 rate limit exceeded).
  • 5xx (Server Error): The server or an upstream proxy failed to fulfill an apparently valid request (500 internal error, 502 bad gateway, 503 overloaded/maintenance, 504 gateway timeout).

Common Debugging Tips & FAQ

  • What is the difference between 401 and 403? 401 Unauthorized means the user is not authenticated yet (missing or expired token/login). 403 Forbidden means the server knows who you are, but your account lacks permission for that resource.
  • When should I return 422 instead of 400? Use 400 Bad Request for malformed JSON or missing protocol syntax, and 422 Unprocessable Entity when the JSON is valid but fails business or field validation rules.
  • How do 502 and 504 differ in Nginx? 502 Bad Gateway usually means PHP-FPM or the upstream app crashed or refused the connection. 504 Gateway Timeout means the upstream accepted the connection but took longer than proxy_read_timeout or fastcgi_read_timeout to respond.

Rate Limiting, Caching & API Error Handling

For well-behaved API clients, pair 429 Too Many Requests and 503 Service Unavailable with a Retry-After header telling callers how many seconds to wait before retrying. For redirects, remember that 301 and 308 are cached aggressively by browsers - test new redirect rules with 302 or 307 first before making them permanent. When building health checks, return 200 OK only when critical dependencies (such as database connectivity) are ready, and 503 when the instance is draining or booting.

Please read the privacy policy (agreement of the cookies usage, other websites embedded content, etc.). If you continue to use the site, we will assume that you agree with our privacy policy.
OkPrivacy Policy