What do HTTP status codes mean?

CS Fundamentals 2 min read
Short answer

1xx is informational, 2xx succeeded, 3xx redirects, 4xx means the request was wrong, and 5xx means the server failed. That split decides whether retrying can help.

#2xx — it worked

  • 200 OK — the general success.
  • 201 Created — a POST created something; the Location header says where.
  • 204 No Content — succeeded, nothing to return. Common for DELETE.

#3xx — go elsewhere

  • 301 Moved Permanently — update your links; search engines transfer ranking.
  • 302 Found / 307 — temporary.
  • 304 Not Modified — your cached copy is still current. This is what makes caching fast.

For SEO, use 301 for permanent moves. A 302 tells search engines to keep indexing the old URL.

#4xx — the request was wrong

  • 400 Bad Request — malformed syntax or payload.
  • 401 Unauthorized — actually means unauthenticated. You did not prove who you are.
  • 403 Forbidden — we know who you are; you are not allowed.
  • 404 Not Found — no such resource.
  • 405 Method Not Allowed — the URL exists, that verb does not.
  • 409 Conflict — clashes with current state, such as a duplicate.
  • 422 Unprocessable Entity — well-formed but failed validation.
  • 429 Too Many Requests — rate limited. Check Retry-After.

401 versus 403 is the pair people get backwards. Send 401 when credentials are missing or invalid, 403 when they are valid but insufficient.

#5xx — the server broke

  • 500 Internal Server Error — an unhandled exception.
  • 502 Bad Gateway — a proxy got a bad response from upstream.
  • 503 Service Unavailable — overloaded or down for maintenance.
  • 504 Gateway Timeout — upstream did not respond in time.

#Retrying

Never retry a 4xx — the same request will fail identically. Retry 429, 502, 503 and 504 with exponential backoff, and cap the attempts.