Everyone knows 404 and 500. The codes that actually cause bugs and security holes are the ones people reach for without checking: 401 vs 403, 302 vs 307, and the criminally underused 429.
HTTP status codes are a shared vocabulary between every client and every server on the web, and most developers speak only a few words of it fluently. That's usually fine — until the day a misused code causes a login form to leak which usernames exist, or a redirect quietly turns a POST into a GET and drops the request body. The codes that cause trouble aren't the obscure ones. They're the common ones people reach for by reflex without checking what they actually mean.
The five classes
Every status code is three digits, and the first digit tells you the category. RFC 9110, the current HTTP specification, states it exactly:
"The first digit of the status code defines the class of response. The last two digits do not have any categorization role."
— IETF RFC 9110, "HTTP Semantics"
So: 1xx informational, 2xx success, 3xx redirection, 4xx the client's fault, 5xx the server's fault. Get the first digit right and you've communicated the most important thing. The same RFC adds a rule that saves clients from breaking when they meet a code they don't know: treat it like the x00 code of its class. An unfamiliar 4xx is handled as a 400. That's why choosing the right class matters more than memorising every specific number.
401 vs 403: the one that leaks information
These two feel interchangeable and aren't. 401 Unauthorized means "I don't know who you are — authenticate." RFC 9110 requires a 401 to carry a WWW-Authenticate header naming at least one challenge, which is a quick way to spot a misused 401: if there's nothing for the client to authenticate with, it probably isn't a 401. 403 Forbidden means the server understood the request and refuses it; RFC 9110 says a server that got valid credentials which aren't enough "ought to respond with the 403".
Using them carelessly creates a real security problem. If a resource returns 403 when it exists but you lack access, and 404 when it doesn't exist, an attacker can map which resources are real by watching the difference. The spec explicitly allows the fix: a server that wishes to "hide" the existence of a forbidden resource "MAY instead respond with a status code of 404". Many security-conscious APIs do exactly that.
The same reasoning applies to login and password-reset forms, though here the leak is usually in the body or timing, not just the code. "No account with that email" versus "wrong password" tells an attacker which addresses are registered. A single generic message and the same status for both cases closes it.
302 vs 307: the redirect that mutates your request
Here's a bug that's hard to trace. RFC 9110 says of 302: "For historical reasons, a user agent MAY change the request method from POST to GET for the subsequent request." Browsers do, and the request body is dropped along the way. If you want a redirect that preserves the method and body, you need 307 Temporary Redirect (or 308 Permanent Redirect for the permanent case — the RFC points to 308 as the method-preserving alternative to 301).
There's also a code built for the opposite intent. 303 See Other says "go GET this other URL", which is the right answer after a successful form POST: the browser loads the result page with a GET, and refreshing it won't resubmit the form. A quick decision table:
| You want | Use |
|---|---|
| Moved for good, method may change (typical page move) | 301 |
| Moved for good, keep method and body (API endpoint move) | 308 |
| Temporary, keep method and body | 307 |
| "Done — now show this page" after a POST | 303 |
| Legacy temporary redirect where method doesn't matter | 302 |
The symptom of getting it wrong is maddening: form submissions that "work" but arrive empty, or an API call that silently becomes a GET after a redirect. When a redirected POST loses its data, the status code is almost always why.
429: the code nobody sends enough
429 Too Many Requests is how a server politely says "slow down". It was defined in RFC 6585, which describes it as the response when "the user has sent too many requests in a given amount of time ("rate limiting")" and says it MAY include a Retry-After header. Retry-After can be a number of seconds or an HTTP date. It's underused — plenty of services just start failing with 500s or dropping connections under load instead of returning a clear 429. That's a missed opportunity: a well-behaved client will back off and retry on a 429, but it can't do the right thing if you never tell it to slow down.
On the client side, honour Retry-After when it's present; when it isn't, back off exponentially and add randomness. An illustrative policy (not a standard) of doubling from 1 second up to a 32-second cap gives waits of 1, 2, 4, 8, 16, 32 and 32 seconds — 95 seconds over seven retries. The randomness matters more than it looks. In a toy simulation for this article, 1,000 clients that all retried at the same moment produced 1,000 requests in a single second; spreading the same retries randomly over eight seconds cut the busiest second to 141. Without jitter, a crowd of polite clients still arrives as a stampede.
The 200-for-an-error anti-pattern
The worst status-code habit is returning 200 OK with an error described in the body — {"success": false, "error": "..."} and an HTTP 200. This breaks every layer that relies on the status code: monitoring thinks everything's healthy, caches may store the "error" as a valid response, and client libraries that check the status see success. The status code is the machine-readable truth about whether the request succeeded; the body is for humans and details. An error is a 4xx or 5xx, full stop — encoding failure inside a 200 is a bug that hides other bugs.
The mirror-image mistake is a 500 for something that is plainly the client's fault, such as a malformed JSON body. That pages an on-call engineer for a typo in someone else's request. Validation failures belong in the 4xx class: 400 for a malformed request, or 422 (Unprocessable Content), which RFC 9110 defines for a request whose content type and syntax are fine but whose instructions the server can't process.
Smaller codes worth knowing
- 204 No Content — success with no body. Good for DELETE or a save that returns nothing. Don't send a body with it.
- 304 Not Modified — the cache-revalidation answer. If clients keep downloading unchanged files, check that your server sends validators (
ETagorLast-Modified) so it can answer 304. - 409 Conflict — the request clashes with the resource's current state, such as two edits racing. More precise than a generic 400.
- 503 Service Unavailable — temporary overload or maintenance. RFC 9110 notes
Retry-Aftercan be sent with it too, telling clients when the service is expected back.
FAQ
Should a failed login return 401 or 400? If the client sent credentials and they were wrong, 401 with a challenge is the HTTP-native answer. Keep the body generic either way.
Is 418 a real code? Not for real use. RFC 9110 lists 418 as "(Unused)" and explains it came from an April 1 RFC, RFC 2324 from 1998, that lampooned HTTP abuses; it was deployed as a joke often enough that the number is now reserved.
Can I invent my own code, like 299? You can, but clients that don't know it will treat it as the class default (200 here). Use headers or the body for extra detail instead.
Look it up, don't guess
When you're not certain which code fits, check rather than reach for a familiar one. An HTTP status codes reference gives you the precise meaning and class in a second, which is faster than shipping a 302 where you needed a 307. When you're debugging a redirect chain, a URL parser helps you inspect exactly where a Location header is pointing. And since so many API responses carry their real detail in a JSON body alongside the status, a JSON formatter makes that payload readable while you confirm the code and the body actually agree. The status line is a contract — the more precisely you use it, the fewer mysteries you ship.