Use HTTP 400 when the request is broken. Use HTTP 422 when the request is readable, but the content fails your app rules. That is the cleanest split. It saves time, logs, support tickets, and developer sanity.

TLDR: A 400 Bad Request means “I cannot parse this mess.” A 422 Unprocessable Content means “I understood it, but the data is wrong.” For example, if 18% of failed checkout requests contain invalid JSON, return 400; if 31% contain a valid JSON body with an expired coupon code, return 422. In a real support queue, that split can cut bug hunting from 20 minutes to 5.

Why this tiny choice matters

HTTP status codes are not decoration. They are road signs. When they are wrong, everyone takes the wrong turn.

A frontend developer sees a 400 and thinks, “The request format is bad.” A backend developer sees a 422 and thinks, “The payload is valid, but the business rule failed.” A QA tester sees both and can sort bugs faster.

When every client error becomes 400, the API becomes a fog machine. Nothing is clear. Logs say “bad request,” but not bad how.

Honestly, it feels like being told your car “does not work” when the real issue is that the key is missing, the tire is flat, or someone filled the tank with orange juice.

What HTTP 400 really means

400 Bad Request means the server cannot process the request because the request itself is malformed.

Think of it as: “I cannot even read this properly.”

Use 400 for problems like these:

  • Invalid JSON syntax.
  • Broken XML.
  • Missing required headers.
  • Invalid query string format.
  • Wrong content type.
  • Bad URL encoding.
  • Request body is cut off.
  • Request is too weird to parse safely.

Example:

{
  "email": "sam@example.com",
  "age": 32,

That trailing comma breaks JSON. The server cannot parse the body. That is a 400.

Another example:

POST /users
Content-Type: text/plain

{"email":"sam@example.com"}

If your API only accepts application/json, this can be a 400. The client sent the wrong kind of package.

What HTTP 422 really means

422 Unprocessable Content means the server understood the request format, but the content failed validation.

Think of it as: “I can read it, but I cannot accept it.”

Use 422 for problems like these:

  • Email is not a real email format.
  • Password is too short.
  • Username is already taken.
  • Start date is after end date.
  • Coupon code is expired.
  • Product quantity is less than 1.
  • Account age does not meet policy rules.

Example:

{
  "email": "potato",
  "password": "123"
}

This is valid JSON. The server can parse it. But the email is nonsense, and the password is weak. That is a 422.

The simple test

Ask one question:

Could the server understand the request structure?

  • No? Return 400.
  • Yes, but the content breaks rules? Return 422.

That is the whole game.

Here is the same idea in plain human speech:

  • 400: “Your message is garbled.”
  • 422: “Your message is clear, but the answer is no.”

A checkout example

Picture an online store. A customer taps “Buy Now.” The frontend sends this:

{
  "productId": 55,
  "quantity": 0,
  "coupon": "SUMMER2020"
}

This request is readable. The JSON is fine. But quantity is invalid. The coupon may also be expired. Return 422.

Now picture this:

{
  "productId": 55
  "quantity": 2
}

There is a comma missing. The server cannot parse the body. Return 400.

Same endpoint. Similar data. Different kind of failure.

Why developers mix them up

Part of the mess comes from history. 400 is old and broad. It has been used for almost anything the client did wrong.

422 started in WebDAV, then became common in APIs. Many frameworks now use it for validation errors. Rails helped make it popular. JSON APIs helped too.

Some teams still avoid 422 because they want fewer status codes. That is fair. But fewer codes can mean more guessing.

Expect to waste time on vague errors if your API returns 400 for every client mistake. A validation bug that should take 30 seconds to spot can turn into a 12 minute log hunt. Multiply that by a team of eight, and your day gets silly fast.

What should the error body say?

The status code is only one clue. The body should explain the problem.

For a 400, say what broke at the request level:

{
  "error": "Bad Request",
  "message": "Invalid JSON body. Unexpected token at line 4."
}

For a 422, show field-level validation errors:

{
  "error": "Unprocessable Content",
  "message": "Validation failed.",
  "fields": {
    "email": "Must be a valid email address.",
    "password": "Must be at least 12 characters."
  }
}

This is kind to humans. It is also kind to machines. Frontend apps can highlight fields. Mobile apps can show better messages. Support teams can paste the exact reason into a ticket.

Common cases and the best status code

  • Malformed JSON: 400.
  • Missing closing brace: 400.
  • Wrong Content-Type: 400 or 415, depending on your API style.
  • Missing Authorization header: 401 is usually better.
  • Valid token, no permission: 403.
  • Valid JSON, invalid email: 422.
  • Valid JSON, duplicate username: 422 or 409.
  • Resource does not exist: 404.
  • Request body too large: 413.

See the pattern? Do not make 400 carry every box in the warehouse. Give each error its own shelf when it makes sense.

400 vs 422 vs 409

There is one tricky neighbor: 409 Conflict.

Use 409 when the request conflicts with the current state of the resource. A classic case is version conflict.

Example:

  • User A edits profile version 7.
  • User B edits the same profile and saves version 8.
  • User A then tries to save old version 7.

That is a 409. The request may be valid, but it fights with the current state.

For duplicate usernames, teams disagree. Some use 422 because the submitted field fails validation. Some use 409 because the username conflicts with an existing resource. Pick one rule. Document it. Stick to it.

A practical rule for teams

Use this policy:

  • 400 for syntax, parsing, and request shape problems.
  • 422 for validation and business rule failures.
  • 409 for state conflicts.
  • 401 and 403 for auth issues.
  • 404 when the target resource is not found.

Then write it down in your API docs. Add examples. Add tests. Do not rely on team memory. Team memory has the shelf life of an open bag of chips.

Final takeaway

400 says the request is broken at the door. 422 says the request got inside, but failed the house rules.

If the server cannot parse it, use 400. If the server can parse it but rejects the meaning, use 422.

That small split makes APIs easier to debug. It makes client apps smarter. It makes logs less annoying. Best of all, it stops “bad request” from being the error code version of a shrug.