HTTP Status Codes: The Complete Developer Guide (2026)
Every HTTP response carries a three-digit status code that tells the client what happened. Knowing what each code means, and when to use each one in your own APIs, is basic to building and debugging web applications. This guide covers every status code you are likely to encounter, with notes on correct usage.
The Five Classes at a Glance
Status codes are grouped by their first digit: 1xx Informational, 2xx Success, 3xx Redirection, 4xx Client Error, 5xx Server Error. The first digit tells you the category; the full three digits tell you the specific outcome.
1xx: Informational
Rare in application code, but worth understanding.
Expect: 100-continue first.Upgrade: websocket and the server responds with 101.2xx: Success
Location header pointing to the new resource's URL.3xx: Redirection
4xx: Client Errors
These mean the client made an error. A well-designed API uses specific 4xx codes so clients know exactly what to fix.
WWW-Authenticate header.Allow header listing the permitted methods.Retry-After and X-RateLimit-* headers so clients know when to retry and how many requests remain.5xx: Server Errors
These mean the server failed. The client's request may have been valid; the problem is on your end.
Retry-After header. Use during planned deployments.Common Mistakes to Avoid
Returning 200 for errors is the most damaging anti-pattern in API design. Some APIs return {"status": "error"} with HTTP 200, which breaks every HTTP client, monitoring tool, and framework that relies on status codes. Always use the correct 4xx or 5xx code.
Returning 404 instead of 403 to hide that a resource exists is sometimes correct. Just not by reflex, since it makes debugging harder for legitimate clients.
Returning 500 for validation errors is also common, and wrong. If the user sent bad data, that is a 400 or 422, not a 500. Reserve 5xx for real server failures.
Quick reference: 2xx = it worked. 3xx = look elsewhere. 4xx = you (the client) did something wrong. 5xx = we (the server) did something wrong.
Debugging API Responses
When debugging API responses, format the JSON body with ToolPry's JSON Formatter to spot the error details quickly. Use the URL Encoder to inspect or construct query parameters. For timestamp-related 401 errors (token expiry), the Timestamp Converter decodes the Unix timestamps in JWT expiry claims instantly.
Status Codes in REST API Design
Choosing the right status code is one of the most important decisions in REST API design. The status code is a contract with your clients: it tells them how to handle the response without parsing the body. A well-designed API uses specific status codes so clients can write simple, reliable error handling. A poorly designed one forces clients to parse every response body to find out whether the request succeeded.
The most important principle: never return 200 for an error. Some APIs return {"status": "error", "message": "Not found"} with HTTP 200. That breaks every HTTP client library, monitoring tool, load balancer, and caching layer that relies on status codes. Always use 4xx and 5xx codes for errors.
Return meaningful error bodies with your status codes. A 400 response should explain which field is invalid and why. A 409 should identify what conflicted. A 429 should include Retry-After. The status code tells the client which category of problem occurred; the body explains the details.
Status Codes and Caching
HTTP caching is built on status codes. Use them well and your API benefits from browser and CDN caching automatically.
200 OK responses are cached according to the Cache-Control header. Cache-Control: max-age=3600 caches the response for an hour. Cache-Control: no-store prevents caching entirely.
301 Moved Permanently is cached indefinitely by browsers. That is correct for permanent URL changes but risky if you use 301 for temporary redirects, because browsers may keep the cached redirect long after you want to remove it. Clear the cache by issuing a 301 to itself with no-cache, then change it to the actual destination.
304 Not Modified is the caching success response. When a client sends If-None-Match or If-Modified-Since and your content has not changed, return 304 with no body, and the client uses its cached copy. This eliminates bandwidth use entirely for unchanged resources.
404 Not Found should not be cached aggressively, since the resource may appear in the future. Avoid setting a long max-age on 404 responses.
5xx responses should never be cached. Server errors are transient; clients should retry without waiting for a cached error to expire.
Monitoring and Alerting by Status Code
Status code distributions tell you more about your application's health than almost any other single metric. Monitoring tools like Datadog, New Relic, and Prometheus all support status code breakdowns. Set alerts for conditions such as a 5xx rate above 0.1% of requests, a 4xx rate rising to more than 10× baseline, a rising rate of 499 (client disconnected), which often points to slow responses, or specific codes like 429 increasing (rate limit pressure).
During a production incident, the status code distribution over time is the first thing to check. A sudden spike in 503s means your servers are overwhelmed or a dependency is down. A spike in 401s might mean a certificate expired or a secret was rotated. A spike in 400s often means a client deployment changed its request format.
Frequently Asked Questions
What is the difference between 401 and 403?
This confuses many developers because the names seem backwards. 401 Unauthorized actually means unauthenticated — the client has not proved its identity. The name is a historical misnomer. 403 Forbidden means unauthorized — the client's identity is known, but it does not have permission for this action. The practical rule: if the client has not logged in (no token, invalid token, expired token), return 401. If the client is logged in but cannot access this resource (wrong role, wrong ownership), return 403.
Should I return 404 or 403 for a resource the user cannot access?
It depends on whether you want to reveal the resource exists. A 403 confirms the resource exists but is forbidden. A 404 reveals nothing. For most APIs, 403 is correct and more useful to developers — they know the endpoint exists and need to fix their permissions. For security-sensitive APIs (admin endpoints, private user data), returning 404 to non-privileged users is correct — it prevents enumeration attacks where attackers probe for the existence of resources.
When should I use 202 Accepted?
Return 202 when the request has been accepted for processing but the processing is not yet complete. The classic use case is asynchronous job queuing: you accept an export request, queue a background job, and return 202 with a location URL the client can poll for status. Include a Location header pointing to the job status endpoint. This pattern is preferable to holding the HTTP connection open for long-running operations, which is fragile across proxies, load balancers, and client timeout limits.
What does 422 Unprocessable Entity mean vs 400 Bad Request?
The distinction is syntactic vs semantic validity. 400 Bad Request means the request is structurally malformed — invalid JSON, missing required headers, a URL that does not make sense. 422 Unprocessable Entity means the request is syntactically valid but semantically wrong — valid JSON, but field values that fail business logic validation (a date in the past when a future date is required, a negative quantity, an email address already registered). Many APIs use 400 for both and that is acceptable; 422 provides finer-grained information when clients need to distinguish parse errors from validation errors.
How should I handle rate limiting with 429?
Return 429 with a Retry-After header (seconds until the client can retry) and X-RateLimit-Limit, X-RateLimit-Remaining, and X-RateLimit-Reset headers on every response so clients can track their usage proactively. Include these headers on successful responses too, not only on 429 — clients should back off before hitting the limit, not after. Implement exponential backoff with jitter in your API clients: on receiving a 429, wait the Retry-After duration, then retry with increasing delays on subsequent 429 responses. Format API error responses to make them easier to read when debugging rate limit issues.