Use HTTP 400 when the server cannot understand the request, and use HTTP 422 when the server understands it but rejects the content. That is the clean rule. If the request is broken at the door, it is a 400 Bad Request. If it gets inside but fails house rules, it is 422 Unprocessable Content.
TLDR: A 400 means “your request is malformed.” A 422 means “your request is well-formed, but the data is wrong.” For example, if your JSON has a missing brace, send 400; if the JSON is valid but the email is banana@, send 422. In one support team’s API logs, 61% of failed signup requests were 422 validation errors, while only 14% were true 400 syntax problems.
Think of it like ordering pizza
You call a pizza shop.
- 400: You shout random noises into the phone. No one can understand the order.
- 422: You clearly ask for a pizza with “credit card number” as a topping. The shop understands you. It still says no.
That is the whole idea. One is about bad request structure. The other is about bad request meaning.
What HTTP 400 really means
HTTP 400 Bad Request is for requests that are broken before your app can safely process them.
The server looks at the request and says, “Nope. I cannot even read this properly.”
Use 400 for things like:
- Invalid JSON syntax.
- Missing required headers.
- A bad query string.
- A request body that is not in the expected format.
- A wrong
Content-Type. - A path parameter with a totally invalid shape.
Example:
{
"email": "sam@example.com",
"age": 30
That JSON is missing a closing brace. The server cannot parse it. That is a 400.
Another example:
POST /users
Content-Type: text/plain
email=sam@example.com
If your API only accepts JSON, this request is wrong at the format level. Send a 400. Do not make the poor developer guess for 20 minutes.
What HTTP 422 really means
HTTP 422 Unprocessable Content is different. The server can read the request. The syntax is fine. The structure is fine. But the values fail validation.
The server says, “I get what you want. I just cannot accept it.”
Use 422 for things like:
- An email field is not a real email.
- A password is too short.
- A username is already taken.
- A date is in the past when it must be future.
- A quantity is below the allowed minimum.
- A field passes syntax checks but breaks business rules.
Example:
{
"email": "banana@",
"password": "123"
}
This is valid JSON. The server can parse it. But the email is bad, and the password is weak. That is a 422.
Honestly, it feels like some APIs flip a coin here. That wastes time. A clear 422 tells the client, “Fix your data, not your request format.”
The easy rule
Ask one simple question:
“Can the server understand the request format?”
- If no, return 400.
- If yes, but the content fails validation, return 422.
That is the cheat code.
Side by side comparison
| Status | Meaning | Common cause | Client action |
|---|---|---|---|
| 400 | Request is malformed | Bad JSON, wrong header, invalid format | Fix syntax or request shape |
| 422 | Request is readable but invalid | Validation failure or business rule issue | Fix field values |
Why this matters for troubleshooting
Good status codes save real time. Bad ones create detective work. Nobody enjoys playing “Guess What the Server Hated” at 4:58 PM.
Say your frontend form suddenly fails. If the API returns 400, your team might inspect headers, JSON encoding, request size, and proxy rules. That is fine if the request is malformed.
But if the real issue is “birthDate must be before today,” then 400 sends people down the wrong path. A 422 points straight at validation. Much better.
Expect to waste time on vague errors. A bad response can add 10 to 30 minutes to a simple bug. Multiply that by five developers. Now you have a tiny bonfire made of salary.
What a good 400 response looks like
A useful 400 response does not just bark “bad request.” It explains what broke.
{
"error": "invalid_json",
"message": "Request body contains invalid JSON.",
"details": {
"line": 4,
"column": 1
}
}
This is helpful. It says the parser failed. It gives a location. It does not blame the user’s cat.
What a good 422 response looks like
A useful 422 response should name the fields that failed.
{
"error": "validation_failed",
"message": "Some fields are invalid.",
"fields": {
"email": "Must be a valid email address.",
"password": "Must be at least 12 characters."
}
}
This is even better for forms. The frontend can show errors beside each field. Users can fix them fast. No mystery. No sad spinner.
Common cases and which code to use
- Broken JSON: Use 400.
- Missing
Content-Type: application/json: Use 400. Some APIs may use 415, but 400 is common. - Required field missing: Usually use 422, if the body is readable.
- Invalid email: Use 422.
- Bad enum value: Use 422.
- Invalid query parameter format: Use 400. Example:
?limit=banana. - Valid value, but not allowed by rules: Use 422.
There is some gray area. Missing fields can start arguments. If the JSON is valid and your app can read it, 422 is often clearer. If the request shape is completely wrong, 400 fits better.
What about 401, 403, and 409?
Do not use 400 or 422 for everything. That creates a junk drawer API.
- 401 Unauthorized: The user is not logged in or the token is missing.
- 403 Forbidden: The user is known but not allowed.
- 404 Not Found: The resource does not exist.
- 409 Conflict: The request conflicts with current state, like a version mismatch.
- 415 Unsupported Media Type: The request body type is not supported.
Pick the most specific status code that helps the client fix the problem.
Best practice for API teams
Set a simple policy. Write it down. Add examples. Then stick to it.
- Use 400 for broken syntax, bad format, and unreadable requests.
- Use 422 for validation failures in readable requests.
- Return machine-friendly error codes.
- Return human-friendly messages.
- Include field-level errors when possible.
- Keep error shapes consistent across endpoints.
Consistency is the boring hero here. It makes logs easier to scan. It makes dashboards cleaner. It makes client code simpler.
Final takeaway
400 means “I cannot understand this request.” 422 means “I understand it, but the content is invalid.” That tiny difference is a huge help during debugging.
If your API returns clear status codes and useful error bodies, developers will fix issues faster. Users will see better messages. And fewer people will shout at harmless JSON brackets.
