Ask five API teams whether a validation failure should return 400 or 422 and you’ll get five answers, usually delivered with confidence. The confusion is understandable: both codes mean “the client did something wrong”, and both are 4xx. But RFC 9110 draws a real distinction, and picking consistently makes your API easier to debug, easier to document, and easier for clients to handle programmatically.
This guide gives you a decision framework, worked examples, and the neighboring codes that often get mixed in. For the full spec-level breakdown of each code, see the 400 Bad Request and 422 Unprocessable Content reference pages.
The distinction in one sentence
- 400 Bad Request — the server cannot understand the request at all: malformed syntax, broken framing, invalid message structure.
- 422 Unprocessable Content — the server understands the request perfectly (syntax and content type are fine) but cannot process the instructions because they’re semantically wrong.
Syntax vs semantics. That’s the whole test.
Worked examples
Malformed JSON body → 400
POST /api/users HTTP/1.1
Content-Type: application/json
{"name": "Ada", "email":}
The JSON doesn’t parse. The server can’t even see what the client intended. This is a syntax failure: 400.
Well-formed JSON, invalid values → 422
POST /api/users HTTP/1.1
Content-Type: application/json
{"name": "Ada", "email": "not-an-email", "age": -3}
The JSON parses cleanly. The server understands every field — and rejects the meaning: the email isn’t an email, the age is impossible. This is a semantic failure: 422.
Wrong content type → 415
POST /api/users HTTP/1.1
Content-Type: text/plain
name=Ada&email=ada@example.com
The endpoint consumes JSON and the client sent form text. Neither 400 nor 422 fits best — 415 Unsupported Media Type exists precisely for this.
Missing authentication → 401, insufficient rights → 403
If the request would be valid but the caller isn’t authenticated, return 401 Unauthorized (yes, the name is historically misleading — it means unauthenticated). If they’re authenticated but not allowed, return 403 Forbidden. Don’t bury auth failures inside 400/422; clients and gateways treat 401 specially (token refresh flows, WWW-Authenticate headers).
A decision flow you can put in your docs
- Can the request be parsed (framing, JSON/XML syntax, required transport headers)? No → 400.
- Is the content type supported? No → 415.
- Is the caller authenticated? No → 401. Allowed? No → 403.
- Does the resource exist? No → 404.
- Does the payload pass business validation? No → 422.
- Does it conflict with current state (duplicate email, version mismatch)? Yes → 409.
Note step 6: uniqueness violations and state conflicts belong to 409 Conflict, not 422 — “this email is already taken” is a conflict with existing state, while “this email is not a valid address” is a semantic validation failure.
Why not just use 400 for everything?
You can — plenty of large APIs do, and RFC 9110 doesn’t forbid it. 400 is the generic client-error code and is always defensible. The argument for 422 is machine-actionable precision:
- A client SDK can map 422 to a field-error display (“show validation messages next to inputs”) and 400 to a generic “request failed” path, without parsing error bodies.
- Monitoring can separate “clients sending garbage” (400 spikes → broken integration or attack) from “users typing bad data” (422 spikes → UX problem).
- API contracts (OpenAPI) become more expressive: 422 responses document your validation schema.
The counterargument: 422 arrived from WebDAV (RFC 4918) and was only promoted to the core HTTP spec in RFC 9110 (2022). Some older proxies, libraries, and docs still treat it as exotic. In practice every modern HTTP client handles it fine.
Whichever you choose, be consistent across every endpoint and document the choice. The worst API is one where /users returns 400 for validation and /orders returns 422 for the same class of error.
Error bodies: the status code is only half the contract
Pair the status with a structured body. RFC 9457 (application/problem+json) is a good default:
{
"type": "https://api.example.com/errors/validation",
"title": "Validation failed",
"status": 422,
"detail": "2 fields failed validation",
"errors": [
{ "field": "email", "message": "must be a valid email address" },
{ "field": "age", "message": "must be >= 0" }
]
}
Clients should branch on the status code for behavior (retry? re-auth? show field errors?) and read the body for display. Never make clients regex your prose to figure out what happened.
While building or debugging these flows, keep a JSON validator handy — half of “the API returned 400” tickets turn out to be a trailing comma in the request body, and you can pinpoint the exact line and column in seconds without sending the payload anywhere.
Quick reference
| Situation | Status |
|---|---|
| Broken JSON / malformed query string | 400 |
| Valid JSON, failed field validation | 422 |
| Unsupported Content-Type | 415 |
| Not logged in / bad token | 401 |
| Logged in, not permitted | 403 |
| Duplicate resource / state conflict | 409 |
| Valid request, missing resource | 404 |
Bookmark the HTTP status code library for the full list with examples in curl, JavaScript and Python — and settle the 400-vs-422 debate on your team once, in writing, before the next code review settles it for you.