HTTP 413 means the request body is too large; HTTP 400 means the request is malformed or invalid in a broader sense. Use 413 Payload Too Large when the server understands the request format but refuses to process it because the payload exceeds a configured limit. Use 400 Bad Request when the request cannot be parsed, violates syntax rules, has invalid framing, or fails basic validation before size is the main issue.
TLDR: HTTP 413 is the right status when a user uploads a 25 MB video to an endpoint capped at 10 MB. HTTP 400 is better when the JSON is broken, the multipart boundary is missing, or the body does not match the expected structure. In one file upload system, raising the allowed image size from 2 MB to 8 MB reduced failed uploads by 42%, while malformed JSON errors stayed almost unchanged. If the request is too big, send 413; if it is badly formed, send 400.
What HTTP 413 Really Means
Table of Contents
HTTP 413 Payload Too Large tells the client that the server rejected the request because the body exceeded a size limit. The request may be perfectly valid. The headers may be clean. The content type may be correct. The only real problem is size.
This often appears during:
- File uploads that exceed application limits
- Large JSON payloads sent to APIs
- Bulk import requests with too many records
- Base64 encoded images inside JSON bodies
- Multipart form submissions with oversized attachments
The older phrase for 413 was Request Entity Too Large. The modern wording is Payload Too Large. Both point to the same class of problem. The server is saying, “I know what this is, but I will not accept this much data.”
What HTTP 400 Really Means
HTTP 400 Bad Request has a wider meaning. It says the server cannot or will not process the request because something about it is wrong. That “wrong” can be syntax, structure, headers, encoding, missing parameters, or invalid field values.
Common 400 causes include:
- Malformed JSON, such as a missing quote or extra comma
- Invalid query parameters
- Missing required fields
- Wrong content type, such as sending text to a JSON endpoint
- Broken multipart form data
- Invalid request headers
A 400 response is often the safe default when the server cannot classify the issue more precisely. Still, it should not be used as a lazy replacement for 413. It drives me crazy when an upload fails with “Bad Request” and gives no hint that the file was 2 MB over the limit. That wastes support time and user patience.
HTTP 413 vs 400: The Practical Difference
The key question is simple: Was the request rejected mainly because of size? If yes, use 413. If no, use 400 or another more specific 4xx status.
| Status | Best Use | Example |
|---|---|---|
| 413 | Payload exceeds a configured limit | User uploads a 60 MB PDF to a 20 MB endpoint |
| 400 | Request is malformed, invalid, or not understandable | API receives broken JSON or missing required fields |
There is some overlap in real systems. A server may stop reading the body early once it detects a size limit. In that case, it may not know whether the full body was otherwise valid. Even then, if the reason for rejection is the limit, 413 is cleaner and more useful.
Why the Right Status Code Matters
Status codes are not decoration. They guide clients, logs, alerts, retries, and user messages. A mobile app can respond to 413 by compressing an image or warning the user before upload. An API client can split a batch into smaller chunks. A support team can spot size issues quickly in logs.
If every request error becomes 400, the signal gets muddy. Developers then dig through request traces, proxy logs, and application metrics just to find out that a 12 MB limit blocked a 13 MB upload. Honestly, that feels like losing five minutes to a problem the server could have explained in one line.
Clear status codes also help monitoring. If 413 rates jump from 0.4% to 6% after a product release, that may mean a new frontend is sending larger images. If 400 rates rise instead, that may point to a client bug, bad validation, or a schema mismatch.
How to Write a Good 413 Response
A useful 413 response should tell the client what went wrong and how to fix it. Keep it brief. Avoid leaking internal server details.
Example response:
{
"error": "payload_too_large",
"message": "The uploaded file exceeds the 10 MB limit.",
"maxSizeBytes": 10485760
}
Good 413 responses often include:
- A clear error code, such as payload_too_large
- The maximum allowed size, when safe to expose
- A short human message
- Advice for the next step, such as compressing the file
For HTTP APIs, include a machine-readable field. For web apps, show a plain message near the upload control. Do not make users guess.
How to Write a Good 400 Response
A good 400 response should describe the validation or syntax issue. It should not say only “Bad Request.” That phrase is accurate but not helpful.
Example response:
{
"error": "invalid_json",
"message": "The request body contains malformed JSON.",
"details": "Unexpected token at line 1, column 18."
}
For validation errors, field-level details help:
{
"error": "validation_failed",
"fields": {
"email": "Must be a valid email address.",
"age": "Must be greater than or equal to 18."
}
}
This tells clients what to change. It also helps frontend teams build better error messages without reading backend code.
Where 413 Is Usually Configured
413 errors can come from several layers. This is a common source of confusion. Your application may allow 50 MB uploads, while the reverse proxy blocks anything over 1 MB.
Check these places:
- Web server, such as Nginx or Apache
- Reverse proxy or load balancer
- Application framework body parser settings
- API gateway request size limits
- Cloud platform upload caps
- WAF rules that reject large bodies
For example, Nginx may return 413 before the request reaches Node.js, Django, Rails, or Java. That means your application logs may show nothing. Expect to waste time on this if logging is weak at the proxy layer.
When 400 May Still Be Correct for a Large Request
Size is not always the only issue. A large request can still deserve 400 if the main failure is bad format. For instance, a 15 MB body sent with Content-Type: application/json may contain random binary data. If the server rejects it because it cannot parse the body as JSON, 400 is reasonable.
Another case is incorrect framing. If the request violates HTTP syntax, has conflicting headers, or uses a broken multipart boundary, the server may return 400 even if the body is also large. The deciding factor is the primary reason for rejection.
Best Practices for Teams
- Use 413 for size limits. Do not hide upload limits behind generic 400 responses.
- Use 400 for syntax and validation failures. Keep messages specific.
- Document maximum payload sizes. Put them in API docs and client rules.
- Align limits across layers. Proxy, gateway, and app settings should match or be clearly ordered.
- Log the source of rejection. Know whether the proxy or app generated the response.
- Return structured errors. Machines and people both need readable feedback.
Final Guidance
Choose 413 when the payload is too large. Choose 400 when the request is malformed, invalid, or cannot be understood. That small distinction saves debugging time, improves user feedback, and gives monitoring data real meaning.
For serious systems, vague errors are expensive. A precise 413 helps clients shrink, split, or retry correctly. A precise 400 helps clients fix structure and validation issues. The server already knows the reason most of the time. It should say it clearly.