# Content-Length Header — Syntax, Values & Examples

> The size of the message body in bytes.

Content-Length tells the receiver exactly how many bytes of body follow, so it knows where the message ends and can show download progress. When the size isn't known in advance, HTTP/1.1 uses `Transfer-Encoding: chunked` instead; HTTP/2 and HTTP/3 frame the body themselves.

- Type: Request & response header
- Category: Content
- Defined in: [RFC 9110 §8.6 — Content-Length](https://www.rfc-editor.org/rfc/rfc9110.html#section-8.6)

## Syntax

```http
Content-Length: <bytes>
```

## Examples

```http
Content-Length: 1024
```

a 1 KB body

## Good to know

- It counts bytes, not characters: `"é"` is one character but two bytes in UTF-8.
- With compression, it's the compressed size.
- A value larger than the body makes clients hang waiting; a smaller one truncates it.
- Servers reject bodies over their limit with [413](https://www.devkult.com/http/413.md), often based on this header alone.

## Who sets Content-Length

Servers, frameworks and HTTP clients calculate Content-Length for you — setting it by hand is a common source of truncated or hanging responses. Check it with `curl -sI https://example.com/ | grep -i content-length`.

## Check it

Fetch only the response headers and filter for Content-Length. In the browser, it's under Response Headers in DevTools → Network.

```sh
curl -sI https://example.com/ | grep -i '^content-length:'
```

## FAQ

### Why is there no Content-Length on my response?

The body is being streamed or compressed on the fly, so the server sends it in chunks (HTTP/1.1) or frames (HTTP/2) instead.

## Status codes it appears with

- [411 Length Required](https://www.devkult.com/http/411.md)
- [413 Content Too Large](https://www.devkult.com/http/413.md)

## Related headers

- [Content-Encoding](https://www.devkult.com/headers/content-encoding.md): Says how the body was compressed — gzip, Brotli or zstd — so the client can decompress it.
- [Content-Type](https://www.devkult.com/headers/content-type.md): States the media type of the body — HTML, JSON, form data, an image — and often its character encoding.

## Further reading

- [413 in nginx: raising the upload limit](https://www.devkult.com/blog/nginx-413-request-entity-too-large.md)

Open the interactive page: https://www.devkult.com/headers/content-length