Use HTTP 400 when the server cannot understand the request, and use HTTP 422 when it understands the request but rejects the meaning of its data. That single rule saves hours of debugging, especially when APIs return vague “Bad Request” messages for every failure. A broken JSON body, missing header, or invalid query format points to 400 Bad Request. A valid JSON body with an impossible email, expired coupon, or business rule violation points to 422 Unprocessable Content.
TLDR: 400 means “I cannot read or accept this request as sent.” 422 means “I read it, but the data is not valid for this action.” For example, if 10,000 checkout API calls fail and 68% are missing a required Content-Type header, those are likely 400 errors; if 24% contain valid JSON but use expired promo codes, those are better returned as 422. Split these codes well, and your logs become useful instead of annoying noise.
Why this distinction matters
Error handling feels boring until production breaks at 2:17 a.m. Then every status code matters. A clean split between 400 and 422 tells developers where to look first. Is the client sending garbage? Or is the client sending clean data that fails validation?
Honestly, it feels like some APIs use 400 as a trash bin for every client-side problem. That makes troubleshooting slower. A frontend developer sees “Bad Request” and starts checking JSON syntax, while the real issue is that startDate is after endDate. That tiny mismatch can cost 20 minutes per incident, sometimes more.
What HTTP 400 Bad Request really means
400 Bad Request is the right response when the request is malformed, incomplete, or not acceptable at the HTTP or parsing level. The server cannot safely process it because the basic request structure has a problem.
Common causes include:
- Malformed JSON: missing braces, trailing commas, bad string escaping.
- Wrong or missing headers: no
Content-Typefor a JSON endpoint. - Invalid query syntax: a date filter in the wrong format.
- Bad URL encoding: spaces, symbols, or reserved characters sent incorrectly.
- Body too strange to parse: XML sent to a JSON-only route.
Example:
POST /users
Content-Type: application/json
{
"email": "sam@example.com",
"age": 31,
The trailing comma makes the JSON invalid. The server cannot parse the body. A 400 response is correct.
A helpful 400 response might look like this:
{
"type": "https://api.example.com/errors/malformed-json",
"title": "Bad Request",
"status": 400,
"detail": "Request body contains invalid JSON at line 5."
}
Notice the message. It does not just say “bad request.” It tells the client what failed. That is the difference between a useful API and a rage machine.
What HTTP 422 means
422 Unprocessable Content means the request is readable and syntactically correct, but the server rejects the content. The server understands the media type. It understands the fields. It just cannot perform the requested action because the data breaks validation or domain rules.
Typical 422 cases include:
- Invalid email format:
"email": "not an email". - Out-of-range values:
"quantity": -3. - Missing required business fields: no billing address for a paid order.
- Rule conflicts: a booking end date before the start date.
- Rejected domain values: a coupon code that exists but is expired.
Example:
POST /users
Content-Type: application/json
{
"email": "sam@example.com",
"age": 12
}
The JSON is valid. The fields are readable. But if your service requires users to be at least 13, the request fails validation. That is a great use of 422.
{
"type": "https://api.example.com/errors/validation",
"title": "Validation failed",
"status": 422,
"detail": "One or more fields failed validation.",
"errors": [
{
"field": "age",
"message": "User must be at least 13 years old."
}
]
}
400 vs 422 at a glance
| Status | Best used when | Example |
|---|---|---|
| 400 | The server cannot parse or accept the request format. | Broken JSON, missing required header, bad query syntax. |
| 422 | The server understands the request but rejects its data. | Invalid field value, failed validation, business rule failure. |
A practical troubleshooting flow
When you see a 400 or 422, avoid guessing. Work from the outside in.
- Check the raw request. Inspect the exact URL, headers, method, and body. Do not trust a pretty client view.
- Validate the body syntax. Paste JSON into a parser. If it fails, expect 400.
- Confirm the media type. A JSON endpoint usually needs
Content-Type: application/json. - Check schema rules. Required fields, string lengths, number ranges, and enum values often cause 422.
- Check business rules. Account status, inventory, permissions, dates, and payment state may reject clean data.
- Compare with a known good request. This finds tiny differences fast.
Expect to waste time if your API gateway, backend service, and validation layer all return different error shapes. One layer says message, another says error, and a third returns plain text. Standardize it. Your future incident reports will be shorter.
When not to use 400 or 422
Not every client error belongs in this pair. Pick a more specific status when it fits.
- 401 Unauthorized: authentication is missing or invalid.
- 403 Forbidden: the user is known but not allowed.
- 404 Not Found: the target resource does not exist or should not be revealed.
- 409 Conflict: the request conflicts with current server state, such as duplicate version updates.
- 415 Unsupported Media Type: the client sends an unsupported format, such as XML to a JSON endpoint.
- 429 Too Many Requests: rate limits were exceeded.
For example, duplicate usernames can be tricky. If the submitted username format is invalid, use 422. If the username is valid but already taken, many APIs use 409 Conflict, because the problem is the current state of the system.
How teams should design error responses
Status codes are only the first clue. The response body must explain what happened in a safe, clear way. A good error response includes:
- A stable error type: useful for client logic and dashboards.
- A human-readable title: short and plain.
- A clear detail message: enough to fix the issue.
- Field-level errors: essential for forms and mobile apps.
- A request ID: priceless when support checks logs.
Use a consistent format such as Problem Details for HTTP APIs. Keep messages specific, but do not leak secrets. “Invalid password” is safer than “Password was correct but account is locked because of fraud review.”
Best rule of thumb
Ask one question: Did the server understand the request structure? If no, return 400 Bad Request. If yes, but the data fails validation or business rules, return 422 Unprocessable Content.
This distinction makes client bugs easier to spot. It keeps dashboards cleaner. It also helps support teams answer users faster. A 400 says, “Fix how you sent it.” A 422 says, “Fix what you sent.” That tiny difference carries a lot of debugging power.