Content-Length Header Explained
What the HTTP Content-Length header does and when it's used.
Published October 13, 2026
Content-Length gives the size of the message body in bytes, letting the receiver know where the body ends.
How it works
If it is wrong, connections can hang or truncate. It is omitted when chunked transfer encoding is used.
The Content-Length header is part of the HTTP message and is case-insensitive in name.
In a real exchange
curl -i https://example.com/
Content-Length: 348
Practical examples
The header
Content-Length: 348Set or use it in code
curl -I https://example.com/file.zip | grep -i content-lengthInspect it
curl -sI https://example.com | grep -i 'content-length'Common mistakes
- Wrong length after compression or modification
- Sending both Content-Length and Transfer-Encoding
- Assuming it equals characters instead of bytes
Key takeaways
- Content-Length: Content-Length gives the size of the message body in bytes, letting the receiver know where the body ends.
- Check it in browser DevTools → Network.
- Test with curl -I before deploying.
FAQ
When is it missing?
With chunked encoding or streaming responses.
Is Content-Length case sensitive?
Header names are case-insensitive; values may not be.