Content-Length

The HTTP Content-Length header indicates the size of the message body in bytes.

Usage

The Content-Length header communicates the exact byte size of the HTTP message body. Clients rely on this value to know when a response has been fully received, making the connection available for reuse in persistent connections under HTTP/1.1.

When a server sends a response with a known body size, the Content-Length header allows the client to allocate the right amount of memory and display accurate progress indicators during downloads. A mismatch between the declared length and the actual body size signals a truncated or corrupted transfer.

This header is mutually exclusive with chunked Transfer-Encoding. When a server streams a response of unknown size, chunked encoding replaces a fixed content length. Under HTTP/2 and HTTP/3, framing handles message boundaries at the protocol level, but Content-Length remains valid for body size validation.

The value is a single non-negative integer representing the number of octets (bytes) in the message body.

Example

A server returns a 3,495-byte JSON response. The client reads exactly 3,495 bytes before considering the message complete.

Content-Length: 3495

A POST request sends a form body. The Content-Length header tells the server how many bytes to expect in the request body.

POST /submit HTTP/1.1
Host: example.re
Content-Type: application/x-www-form-urlencoded
Content-Length: 27

field=value&other=something

A response using chunked transfer encoding omits the Content-Length header entirely. The Transfer-Encoding header takes precedence.

Transfer-Encoding: chunked

Takeaway

The Content-Length header declares the exact byte size of a message body, enabling clients to detect complete transfers, allocate resources efficiently, and reuse persistent connections.

See also

Last updated: March 11, 2026