Selective byte retrieval from an HTTP resource reduces bandwidth usage and speeds up diagnostics when only a fragment of a file is needed. Byte slicing is helpful for reading headers embedded in binaries, sampling sections of large media objects, or validating how storage backends handle partial content. Narrowing the transfer to a specific region also lowers load on servers that frequently serve very large files.
The HTTP Range mechanism uses the Range: bytes=start-end request header so that the server can respond with only the requested interval instead of the entire object. When a range is accepted, the response typically returns status code 206 Partial Content, along with Content-Range metadata describing the segment and total size. cURL exposes this functionality through the –range option, which maps directly to the underlying byte-range semantics and writes the returned slice to the chosen output file.
Range requests depend on correct offsets and server support. Some endpoints ignore range headers and reply with a full 200 OK response, while others return 416 Range Not Satisfiable when the requested region lies outside the object size. Partial content from structured formats such as archives or video containers may not be independently meaningful, so any extracted fragment should be treated as a diagnostic sample rather than a complete usable file.
Steps to download a specific byte range with cURL:
- Open a terminal in an environment where cURL is installed.
cURL is available on most Unix-like systems and Windows; package managers or official binaries provide the command when absent.
- Request a fixed byte interval from an HTTP resource using the –range option so that the response is written to a file.
$ curl --range 0-99 https://example.com/large-file.bin --output first-100-bytes.bin % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 100 100 100 0 0 5000 0 --:--:-- --:--:-- --:--:-- 5000
Values supplied to –range are inclusive, so 0-99 retrieves 100 bytes starting from offset zero into the first-100-bytes.bin file.
- Use open-ended and suffix ranges when a noninitial segment of the resource is required.
$ curl --range 100- https://example.com/large-file.bin --output from-byte-100.bin $ curl --range -500 https://example.com/large-file.bin --output last-500-bytes.bin % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 123k 100 123k 0 0 12300 0 --:--:-- --:--:-- --:--:-- 12300 ##### snipped #####
Some servers ignore byte ranges or disable partial content, causing a full 200 OK response or a 416 Range Not Satisfiable error, which can unexpectedly transfer entire large files or signal invalid offsets.
- Check the size of a saved partial file in bytes to confirm the requested interval length.
$ wc -c first-100-bytes.bin 100 first-100-bytes.bin
The first column of wc byte output should match the expected length, such as 100 for a 0-99 range request.
- Inspect response headers to confirm that the server honored the byte range request.
$ curl --range 0-99 --silent --output /dev/null --dump-header - https://example.com/large-file.bin HTTP/1.1 206 Partial Content Accept-Ranges: bytes Content-Length: 100 Content-Range: bytes 0-99/123456 Content-Type: application/octet-stream ##### snipped #####
Reliable indicators of a successful range request include status code 206 Partial Content, an Accept-Ranges: bytes header, a Content-Range header that matches the requested offsets and object size, and saved file sizes aligning with the selected intervals.
Mohd Shakir Zakaria is a cloud architect with deep roots in software development and open-source advocacy. Certified in AWS, Red Hat, VMware, ITIL, and Linux, he specializes in designing and managing robust cloud and on-premises infrastructures.
Comment anonymously. Login not required.
