An HTTP 400 Bad Request response indicates that the server cannot or will not process the request due to something that is perceived to be a client error, such as malformed request syntax, invalid request message framing, or deceptive request routing.
HTTP 400 at a glance
- Status: 400
- Phrase: Bad Request
- Class: 4xx Client Error
- Specification: RFC 9110 Section 15.5.1
- Typical context: Malformed payload syntax, invalid URI encoding, or unparseable headers
- Client retry: Unsafe without correcting the request construction
What a 400 response tells you
When a server returns an HTTP 400 status code, specific protocol facts are established:
- The server reached the client error evaluation stage: The server (or an intermediary) inspected the request and determined that its syntax, framing, or headers violate protocol or format constraints.
- The request was rejected before full execution: The server declined to complete normal request processing because it could not reliably parse the input.
- Resending the exact same request will yield the same error: Because 400 represents a client-side syntax or construction defect, repeated attempts without modifying the request will continue to fail.
What a 400 does not tell you
While an HTTP 400 confirms that the request was rejected due to client-side issues, it does not automatically pinpoint the exact layer of failure without examining the response body or server logs:
Client -> Web Server / Reverse Proxy -> Application Parser -> Business Logic
Receiving an HTTP 400 does not prove:
- The authentication token is invalid (which warrants 401).
- The user lacks sufficient permissions (which warrants 403).
- The requested resource path does not exist (which warrants 404).
- The business validation rules failed on syntactically valid data (which commonly warrants 422).
- The backend database or downstream service experienced an internal error.
Similar status codes
Several 4xx status codes describe related client-side rejection conditions. Understanding their distinct boundaries ensures accurate API diagnostics:
422 Unprocessable Content
The server understands the content type and the syntax of the request entity is correct, but was unable to process the contained instructions (e.g., missing required fields, field value out of range, or semantic validation failure).
401 Unauthorized
The request lacks valid authentication credentials for the target resource, or authentication was provided but failed verification.
404 Not Found
The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.
415 Unsupported Media Type
The origin server refuses to service the request because the payload is in a format not supported by this method on the target resource (e.g., sending XML to an endpoint configured exclusively for JSON).
For an in-depth comparison between syntax errors and semantic validation failures, see our dedicated guide on HTTP 400 vs 422.
Diagnostic scenarios
Two common scenarios demonstrate how HTTP 400 errors occur in modern web applications:
Scenario 1: Malformed JSON serialization or syntax errors
A frontend client or automated script constructs an HTTP POST or PUT request. Due to improper serialization, string concatenation, or unescaped characters, the payload arrives with syntax errors (such as trailing commas, mismatched quotes, or invalid Unicode characters). The web framework’s body parser fails deserialization before invoking the endpoint controller and immediately returns HTTP 400.
Scenario 2: Malformed URI encoding in query parameters
A client constructs a dynamic query URL without safely passing parameters through a standard encoding function (such as encodeURIComponent). When special characters (e.g., %, &, +) appear unescaped or with incomplete percent sequences (e.g., ?search=data%2), the reverse proxy or HTTP server rejects the malformed URI with HTTP 400.
Common causes of HTTP 400
Malformed request payload syntax
The client transmitted a request body with syntax errors, such as unclosed JSON strings, trailing commas, or invalid escape sequences that prevent parser execution.
Invalid query parameter or URI encoding
The request URI contains unencoded characters, malformed percent-encoding sequences, or parameter structures that the server routing layer cannot parse.
Oversized or invalid request headers
The client sent HTTP request headers or cookies exceeding server buffer limits, or headers containing illegal characters.
Invalid request framing or chunked encoding
The client sent conflicting Content-Length and Transfer-Encoding headers, or malformed chunked transfer encoding boundaries.
Headers you may encounter
HTTP 400 responses often include specific headers depending on the server stack and failure mode:
Content-Type: Typicallyapplication/problem+json(RFC 7807) orapplication/jsondescribing the specific parsing error.Date: Indicates the date and time when the response originated.Connection: May be set tocloseif the bad request involved framing defects or HTTP protocol desynchronization risks.WWW-Authenticate: Not expected on 400 responses; if authentication is the primary issue, status 401 must be returned instead.
Troubleshooting flow
When troubleshooting an HTTP 400 error, follow a structured diagnostic path:
HTTP 400 Bad Request
|
+-- Does the response contain a Problem Details body?
|
+-- Yes: Check 'detail' field for specific parser line/column failure.
|
+-- No: Inspect raw request message directly.
|
+-- Is the JSON / payload syntactically valid?
| |
| +-- No: Fix client serialization (trailing commas, quotes).
| +-- Yes: Check Content-Type header and URI encoding.
|
+-- Are request headers or cookies unusually large (> 8KB)?
|
+-- Yes: Clear stale cookies or reduce header payload.
What to check before changing backend code
Before modifying server-side application logic or disabling validation rules, inspect the request from the client side:
- Validate the raw payload with a standalone linter or strict JSON parser.
- Verify that the
Content-Typeheader matches the payload format (application/json,multipart/form-data, etc.). - Check all query string values for correct percent-encoding of reserved characters.
- Test the request with minimal headers using
curlto rule out header buffer overflow caused by accumulated cookies. - Confirm whether the API endpoint expects status 422 instead of 400 for business validation failures.
How to verify the fix
Reproduce the request with curl using the --verbose (-v) flag to inspect headers, payload transmission, and response details:
curl -i -X POST https://api.example.test/v1/users \
-H "Content-Type: application/json" \
-H "Authorization: Bearer test-token" \
-d '{"name": "Alex", "email": "alex@example.test"}'
Inspect the response status line and body to ensure status 200 OK or 201 Created is returned once the malformed syntax is corrected.
Remediation paths to evaluate
If the error is caused by malformed JSON syntax
Ensure client-side HTTP libraries serialize payloads using standard JSON.stringify() rather than manual string interpolation.
If the error is caused by URI parameter encoding
Use standard URL encoding utilities (such as encodeURIComponent() in JavaScript or urllib.parse.quote() in Python) for all dynamic query parameters.
If the error is caused by oversized header buffers
Clear browser cookies for the domain or configure the reverse proxy (e.g., NGINX large_client_header_buffers) with appropriate buffer limits if large headers are legitimate.
If the error is caused by Content-Type mismatch
Ensure the client explicitly includes the required Content-Type header matching the transmitted entity representation.
FAQ
What is the difference between HTTP 400 and HTTP 422?
HTTP 400 Bad Request signifies that the server could not parse the request due to malformed syntax or protocol framing errors. HTTP 422 Unprocessable Content indicates that the payload was syntactically valid (such as well-formed JSON), but failed semantic or business validation rules.
Does an HTTP 400 indicate a server crash?
No. An HTTP 400 indicates that the server’s HTTP parser or validation layer actively intercepted and rejected an invalid request. The server is operating as designed.
Can a client retry an HTTP 400 request immediately?
No. Because HTTP 400 indicates a defect in how the request was formed, retrying without modifying the request syntax, headers, or query parameters will produce the exact same error.
Key takeaway
HTTP 400 Bad Request indicates that the server rejected the request due to client-side syntax, framing, or encoding errors. Before making backend code changes, isolate and inspect the raw request payload, verify proper percent-encoding of URI parameters, and ensure that request headers conform to protocol limits.