Request Entity Too Large: HTTP 413 vs HTTP 400 for Troubleshooting Request Size Errors

Use HTTP 413 when the request body is too big. Use HTTP 400 when the request is broken, confusing, or does not match the rules. That single choice saves hours of bug hunting. It tells the client, “Your file is fat,” not “Your request is cursed.”

TLDR: 413 Request Entity Too Large means the server understood the request, but the body was bigger than allowed. 400 Bad Request means the server could not accept the request because it was malformed or invalid. For example, if your API allows 10 MB uploads and a user sends 14 MB, return 413. One team saw support tickets drop by 28% after changing oversized upload errors from 400 to 413, because developers stopped chasing fake JSON bugs.

Meet the two error codes

HTTP errors are like tiny traffic cops. Some are helpful. Some just wave their arms and yell.

HTTP 413 has one job. It says the request payload is too large. The payload is the request body. Think file upload, JSON body, form data, video, image, or a giant blob of text from someone who pasted a whole novel into a comment box.

HTTP 400 is broader. It says the request is bad. Maybe the JSON is broken. Maybe a required field is missing. Maybe the content type is wrong. Maybe the body is nonsense. It is the “something is off” code.

Honestly, it feels like getting a 400 for a big upload is like asking, “Why did my suitcase fail airport security?” and hearing, “Bad suitcase.” Thanks. Super useful.

What 413 really means

413 Request Entity Too Large is also known as 413 Payload Too Large. The name changed, but the idea stayed the same.

The server is saying:

  • I can read your request.
  • I know what you want.
  • But this body is bigger than my limit.

That limit can come from many places. It may not be your app code. It may be hiding in a proxy, load balancer, web server, API gateway, framework, or cloud service.

Common examples include:

  • Nginx: client_max_body_size
  • Apache: LimitRequestBody
  • IIS: maxAllowedContentLength
  • Express: body parser limits
  • Spring Boot: multipart upload settings
  • Cloud proxies: fixed upload caps

That is why 413 can feel spooky. Your app may never see the request. The gateway may reject it first. So your app logs show nothing. Then everyone stares at each other. Fun times.

What 400 really means

400 Bad Request means the request has a problem that is not just size.

Use 400 when:

  • The JSON is invalid.
  • The body is empty but required.
  • The request uses the wrong Content-Type.
  • A field has the wrong type.
  • A required value is missing.
  • The form data is not parseable.

Here is a simple rule. If the user can fix the problem by sending a smaller body, use 413. If they must fix the structure or values, use 400.

For example, this is a 400 problem:

{ "email": "cat@example.com", "age": "banana" }

If your API expects age to be a number, “banana” is funny, but not valid.

This is a 413 problem:

POST /upload
Content-Length: 52428800

If the max upload size is 10 MB, a 50 MB file is not a mystery. It is too big.

Why the wrong code wastes time

A bad error code sends people down the wrong hallway.

If an API returns 400 for a giant image upload, the client team may inspect JSON, headers, tokens, and field names. They may retry five times. They may add logs. They may question their life choices.

Then someone checks the upload limit and sees the answer in nine seconds. The file was too large.

It drives me crazy that some systems hide this behind generic messages like “Bad request.” That message is not helpful. It is a shrug wearing a badge.

A better response looks like this:

{
  "error": "payload_too_large",
  "message": "Maximum upload size is 10 MB.",
  "maxBytes": 10485760
}

Short. Clear. Useful. No guessing game.

How to troubleshoot 413 errors

Start with the size. Always. Check the actual body size, not the guessed size.

Follow this quick path:

  1. Check the response code. Is it really 413?
  2. Check the response body. Does it mention a limit?
  3. Check the upload size. Use bytes, not vibes.
  4. Check every layer. Browser, app, proxy, server, gateway.
  5. Check logs near the edge. The app may not receive the request.

Also check if the client uses Base64. Base64 makes data about 33% larger. A 7.8 MB image may become a 10.4 MB JSON string. Surprise. Now it breaks.

Multipart uploads are often better for files. They avoid stuffing large binary data inside JSON. They also make limits easier to manage.

How to troubleshoot 400 errors that look like size errors

Sometimes 400 appears during a large request, but size is not the cause.

Check these things:

  • Malformed JSON: Missing braces are tiny villains.
  • Wrong content type: Sending JSON as plain text can fail.
  • Bad multipart boundary: File uploads need clean form boundaries.
  • Invalid compression: A bad gzip body can trigger 400.
  • Missing fields: Large does not mean complete.

If the request fails even when tiny, it is likely not a size issue. Send the smallest valid request. Then grow it. Add fields. Add file size. Watch where it breaks.

This test is boring. It also works.

Client side tips

Clients should not wait for the server to yell.

If the max file size is 10 MB, show that before upload. Reject a 25 MB video in the browser or mobile app. Save bandwidth. Save time. Save the user from watching a progress bar reach 99% and die. That one hurts.

Good client behavior includes:

  • Show the max file size near the upload button.
  • Validate before sending.
  • Compress images when safe.
  • Use chunked uploads for large files.
  • Show a friendly error message.

A nice message says:

“This file is 18 MB. The limit is 10 MB. Please upload a smaller file.”

That is much better than:

“Request failed.”

Request failed? Great. So did my mood.

Server side tips

Servers should return the clearest code possible.

Use 413 when the body is too large. Include the max size. If possible, include a retry hint. Some systems also use the Retry-After header when the limit is temporary, but size limits are usually fixed.

Use 400 when the request is malformed or invalid. Be specific. Say what field failed. Say what format was expected.

Also keep limits consistent. If Nginx allows 20 MB, but your app allows 10 MB, users may get mixed errors. Pick a limit. Apply it across layers. Document it.

A simple decision cheat sheet

  • File too big? Return 413.
  • JSON too big? Return 413.
  • Broken JSON? Return 400.
  • Wrong field type? Return 400.
  • Missing required field? Return 400.
  • Headers too large? Consider 431 Request Header Fields Too Large.

The clean rule is simple: size problem equals 413. Shape problem equals 400. When servers speak clearly, clients fix bugs faster. Everyone gets fewer mystery errors. And nobody has to blame the poor JSON parser for a 40 MB cat photo.