HTTP 4xx client error status codes
The 4xx class means the server believes the client got something wrong: the syntax, the credentials, the permissions, the target, or the rate. Returning the most precise 4xx code — and a clear, machine-readable error body — turns a frustrating failure into something a developer can fix in seconds. The difference between 400 and 422, or 401 and 403, is not pedantry; clients branch on these codes. Search the reference above by number, name, or symptom to find the right one.
How it works
When the server detects a client-side problem, it returns a 4xx code and should not retry the request unchanged (the exceptions are 408 Request Timeout and 429 Too Many Requests, which invite a retry). Several codes require specific headers to be valid: 401 needs WWW-Authenticate, 405 Method Not Allowed needs Allow, and 429 should carry Retry-After. A good REST API pairs the status code with a structured body — commonly an RFC 9457 Problem Details document with type, title, status, and detail fields — so clients can display a helpful message and developers can debug without guessing.
Tips and examples
- Distinguish authentication from authorization:
401(who are you?) versus403(you may not). Mixing them confuses clients and security audits. - Use
422for validation failures and return a field-level error list so forms can highlight exactly what to fix. - On
429, always setRetry-After; well-behaved clients use it to back off instead of hammering your service. - Prefer
410 Goneover404for resources you have intentionally and permanently retired — it is clearer and more cache-friendly for crawlers.