HTTP status codes, explained practically

Every response starts with a three-digit number, and the number is a diagnosis. This guide skips the RFC recital and focuses on what each family means for your debugging — plus the distinctions that actually matter.

The five families in one paragraph

The first digit is the class. 1xx means the conversation is still in progress (you almost never see these). 2xx means success. 3xx means the answer lives somewhere else. 4xx means your request is the problem. 5xx means the server failed while your request was fine. That split is the whole debugging strategy: 4xx — fix the request; 5xx — go read the server logs; 3xx — follow the Location chain.

401 vs 403: the distinction that saves hours

The most confused pair in web development. 401 Unauthorized really means "unauthenticated" — the server does not know who you are. Your token is missing, expired, malformed, or from the wrong issuer. The fix is re-authentication. 403 Forbidden means the server knows exactly who you are and is refusing — the account lacks the role, the IP is blocked, or a WAF rejected the payload. Re-authenticating into the same account will change nothing.

The practical test: if logging in again fixes it, it was 401 territory. If not, stop hammering the login flow and check permissions, IP allowlists, or the WAF logs.

The redirect codes are not interchangeable

  • 301 vs 308: both permanent; 308 additionally promises the request method stays unchanged. For migrating an API endpoint that receives POSTs, 308 is the correct answer — 301 lets clients downgrade POST to GET and lose the body.
  • 302 vs 307: the temporary equivalents of the same distinction. In practice browsers have always switched POST to GET on 302 despite the spec; 307 forbids it.
  • 303: "look at the result over here with GET" — the standard post-form redirect that prevents double submissions.
  • 304 Not Modified: not an error at all — it is your cache working. Only visible in dev tools with caching enabled; people routinely "fix" a 304 that was never broken.

Two operational traps: permanent redirects are cached by the browser, so a mistakenly deployed 301 keeps redirecting even after you fix the server — test with a private window or curl -v. And redirect loops usually surface as a 4xx-family browser error (ERR_TOO_MANY_REDIRECTS), not a clean status from any single hop.

502 vs 503 vs 504: ask your architecture diagram

These three tell you where the failure is, if you know your topology. 502 Bad Gateway: the proxy (nginx, load balancer, CDN) reached out and the upstream answered nonsense or nothing — typically a crashed or restarting application process, or an app listening on the wrong port. 504 Gateway Timeout: the upstream exists but took too long — slow database queries, long-running jobs, deadlocks. Raising the proxy timeout treats the symptom; profile why the upstream is slow first. 503 Service Unavailable: deliberate unavailability — maintenance mode, overload shedding, or in Kubernetes, no ready pods behind the service.

Client-side, the distinction collapses to one rule: 5xx errors are never fixed by editing the request. Retrying with exponential backoff is reasonable (the server asked for nothing), but the real fix lives in logs and infrastructure.

The 4xx codes with real-world sharp edges

  • 429 Too Many Requests: hit a rate limit. Read Retry-After, back off exponentially, and cap retries in scripts — continuous hammering usually extends the ban.
  • 413 Payload Too Large: often a proxy default, not the application — nginx's client_max_body_size and gateway limits are the usual culprits behind "uploads fail above 1 MB".
  • 431: header block too large — nearly always an enormous Cookie header accumulated over months. Clearing cookies for the domain fixes it instantly.
  • 400 vs 422: 400 means unparseable (syntactically broken JSON); 422 means parsed but rejected by validation (missing field). When an API returns 400 on valid-looking JSON, check Content-Type first.

A debugging routine that works

  1. Look at the real response, not the UI's interpretation: browser Network panel or curl -v. Read the status, then the body — 4xx bodies usually state the exact validation failure.
  2. Diff the request against intent: method, path, headers (Content-Type, Authorization), payload. Half of 4xx errors die here.
  3. Follow the class: 3xx — trace the Location chain; 4xx — fix the request or credentials; 5xx — leave the client, open server logs at the request timestamp.

For a full searchable list with per-code causes and fixes, use the HTTP status code lookup tool. It pairs naturally with the URL encoder (malformed percent-encoding is a classic source of 400s) and the JWT decoder when the 401 turns out to be an expired token.