Command line

Hex-Dumping a 64 MiB Binary, Measured: xxd vs hexdump vs od

The same 64 MiB binary dumps in 0.68 seconds with xxd -p and 6.57 with hexdump -C, but the speed table is the least interesting part. The fastest form is also the only reversible one, the default od and hexdump output silently drops repeated lines, and bare hexdump prints byte-swapped word pairs instead of bytes.

Written November 10, 2026 · 12 min read

By the end of this guide
  • The table: xxd -p is fastest; the canonical forms cost 5 times as much
  • The same bytes, six different lines
  • Bare hexdump prints word pairs, not bytes
  • The that eats your output

What this guide is

One binary, six arms, three reps each. The binary is 64 MiB of random bytes from /dev/urandom, 67,108,864 bytes, and every arm dumps the same file to a file on tmpfs. Every rep is checked the same way: the output byte count and the sha256 of the output must be identical across all three reps, so a timing number can never come from a run that printed something different. The question is the one people ask before dumping a firmware image or a core file: which tool shows the bytes, how fast, and what does its default output hide.

The answer is a correction in both directions. The three tools print the same bytes at wildly different speeds: the canonical display costs 5.31 times the plain xxd form for the same visual output. But the fastest form is also the only one that can turn the dump back into the file, and the default od and hexdump output is lossy on repetitive data in a way that breaks line-by-line parsing. Speed is the table; reversibility and elision are the guide.

The table: xxd -p is fastest; the canonical forms cost 5 times as much

Wall seconds, medians of three runs, fresh tonight. Every rep returned rc=0, and every arm produced byte-identical output across its three reps.

  • xxd -p: fresh median 0.6848, reps 0.6841, 0.6848, 0.6919. Night before: 0.6861, reps 0.6817, 0.6861, 0.6935. Output 136,454,691 bytes.
  • xxd (default): fresh median 1.2378, reps 1.1820, 1.2378, 1.2990. Night before: 1.2214, reps 1.1733, 1.2214, 1.2443. Output 285,212,672 bytes.
  • hexdump (bare): fresh median 2.6602, reps 2.6144, 2.6602, 2.6793. Night before: 2.6186, reps 2.6074, 2.6186, 2.6966. Output 201,326,600 bytes.
  • od -A x -t x1: fresh median 5.5569, reps 5.5556, 5.5569, 5.5667. Night before: 5.5122, reps 5.5079, 5.5122, 5.5435. Output 233,832,456 bytes.
  • od -A x -t x1z: fresh median 6.0558, reps 6.0543, 6.0558, 6.0865. Night before: 6.0916, reps 6.0760, 6.0916, 6.0999. Output 317,718,536 bytes.
  • hexdump -C: fresh median 6.5670, reps 6.5562, 6.5670, 6.5777. Night before: 6.5693, reps 6.5439, 6.5693, 6.7788. Output 331,350,025 bytes.

xxd -p is the fastest arm at 0.6848 seconds, 93.5 MiB/s of input throughput. Plain xxd is 1.81 times slower. Bare hexdump is 3.88 times xxd -p. od -A x -t x1 is 8.11 times, od -A x -t x1z is 8.84 times, and hexdump -C is 9.59 times. The same-format pair is the sharpest comparison: hexdump -C costs 5.31 times xxd tonight (5.38 the night before) and od -A x -t x1z costs 4.89 times (4.99 the night before) for the same visual output, offset plus sixteen hex bytes plus an ASCII column. The ranking is identical on both nights and every ratio moved by less than 2 percent, so the gap is stable and the exact ratio is one machine's.

The ASCII column costs real time. Dropping it from od, -t x1z to -t x1, saves 0.50 seconds tonight, 9.0 percent (0.58 seconds, 9.5 percent the night before). Dropping the offsets and the ASCII column from xxd, plain xxd to xxd -p, saves 0.55 seconds, 44 percent, and halves the output from 285 MB to 136 MB. The output sizes are the reason: every arm writes 136 to 331 MB of formatted text for 64 MiB of input, so the numbers include the cost of formatting and writing that text, not just reading the binary.

The same bytes, six different lines

The first 32 bytes of the corpus, dumped six ways. The bytes are the same in every line; the layout is what differs.

Terminal
$ xxd sample.bin
00000000: a7c8 f646 02ad b8c6 3e5d 0a3f cb15 46bb  ...F....>].?..F.
00000010: c94b a92a 0844 0039 fbe5 3afb 51ea adeb  .K.*.D.9..:.Q...

$ xxd -p sample.bin
a7c8f64602adb8c63e5d0a3fcb1546bbc94ba92a08440039fbe53afb51ea
adeb

$ hexdump sample.bin
0000000 c8a7 46f6 ad02 c6b8 5d3e 3f0a 15cb bb46
0000010 4bc9 2aa9 4408 3900 e5fb fb3a ea51 ebad
0000020

$ hexdump -C sample.bin
00000000  a7 c8 f6 46 02 ad b8 c6  3e 5d 0a 3f cb 15 46 bb  |...F....>].?..F.|
00000010  c9 4b a9 2a 08 44 00 39  fb e5 3a fb 51 ea ad eb  |.K.*.D.9..:.Q...|
00000020

$ od -A x -t x1z sample.bin
000000 a7 c8 f6 46 02 ad b8 c6 3e 5d 0a 3f cb 15 46 bb  >...F....>].?..F.<
000010 c9 4b a9 2a 08 44 00 39 fb e5 3a fb 51 ea ad eb  >.K.*.D.9..:.Q...<
000020

$ od -A x -t x1 sample.bin
000000 a7 c8 f6 46 02 ad b8 c6 3e 5d 0a 3f cb 15 46 bb
000010 c9 4b a9 2a 08 44 00 39 fb e5 3a fb 51 ea ad eb
000020

Three details in those lines are worth reading closely. First, the offsets differ: xxd and hexdump -C count in hex with eight digits, bare hexdump counts in octal with seven digits, od with -A x counts in hex with six digits. Second, od wraps its ASCII column in > and < where xxd and hexdump -C use |; a parser written for one will misread the other. Third, the bare hexdump line reads c8a7 where every other tool reads a7c8. That is the next section.

Bare hexdump prints word pairs, not bytes

With no format flag, hexdump prints two-byte hex words in the machine's native byte order, not single bytes. The manual says the default display is very similar to the -x output, and -x is two-byte hexadecimal: eight space-separated, four-column, zero-filled, two-byte quantities per line. On this little-endian box that means each pair of bytes is printed with the bytes swapped. The first two bytes of the file are a7 c8, and bare hexdump prints c8a7. The next two are f6 46, printed as 46f6.

The swap is silent. Nothing in the output marks it as word pairs, and the line looks exactly like a hex dump until you compare it byte by byte against another tool. A reader who copies the first word off a bare hexdump line and pastes it into a patch or a comparison has the bytes backwards. The fix is to ask for single-byte output explicitly: hexdump -C for the canonical form, or od -A x -t x1 for one-byte hex without the ASCII column. The manual names the portability rule directly: the default format and the -x, -d, and -o options use multi-byte format units displayed in the system's native byte order, so the same input produces different output on little-endian and big-endian systems, and single-byte formats such as -C are the byte-order independent choice.

The bare form is still the third-fastest arm at 2.6602 seconds, and its output is the third-smallest at 201 MB, because eight four-column words carry the same sixteen bytes in fewer characters than sixteen two-column bytes. That is the trade it makes: it is fast and compact because it prints words, and the words are the trap. Use it only when you know the input is being read as words, and never when you are reading individual bytes.

The * that eats your output

On the all-zeros corpus, 64 MiB of zeros, the default od and hexdump output collapses. The numbers are identical on both nights:

  • od -A x -t x1z default: 3 lines, 85 bytes. One data line, a * line, and a final offset line.
  • od -A x -t x1z -v: 4,194,305 lines, 317,718,536 bytes.
  • hexdump -C default: 3 lines, 90 bytes.
  • hexdump -C -v: 4,194,305 lines, 331,350,025 bytes.
  • xxd: 4,194,304 lines, 285,212,672 bytes, with no flag and no elision.

The manuals both document the behavior. Hexdump's -v option causes it to display all input data, and without it any number of groups of output lines identical to the immediately preceding group are replaced with a line comprised of a single asterisk. Od's -v is the same flag under a different name: do not use * to mark line suppression. The flag exists because the default is a display convenience, and the convenience is lossy: the default output does not contain the lines it replaced. Any script that counts lines, greps the dump for a repeated pattern, or pipes it into a parser that expects one line per sixteen bytes gets three lines where 4,194,304 belong.

One counting detail matters when you do pass -v. Od and hexdump print 4,194,305 lines on the zero corpus: 4,194,304 data lines plus one trailing offset-only line. Xxd prints exactly 4,194,304, no trailing offset line. The difference is one line, and it is the difference between a line count that equals the number of sixteen-byte groups and one that is off by one. A script that asserts the dump has exactly 4,194,304 lines will fail on od and hexdump with -v and pass on xxd, for the same input.

A real file with partially repetitive regions elides proportionally less: a run of identical sixteen-byte groups collapses to one line plus a *, and the rest of the file prints in full. Do not claim every repetitive file collapses to three lines. Do claim that default od and hexdump output is not a complete record of the input, and that -v, or xxd, is the fix when completeness matters.

Plain hex is reversible; the display forms are not

xxd -p output is a plain hex stream with no offsets, no ASCII column, and no grouping. That makes it the only arm whose output can be turned back into the file with the same tool: xxd -p rand.bin | xxd -r -p reproduces the source byte-identically. The probe ran it once tonight: encode plus decode wall 2.6366 seconds (2.6603 the night before), 67,108,864 bytes out, sha256 match against the source. The manual states the rule: use the combination -r -p to read plain hexadecimal dumps without line number information and without a particular column layout, and additional whitespace and line breaks are allowed anywhere.

The display forms cannot do this. An xxd default dump carries offsets and an ASCII column that -r must strip, and an od or hexdump -C dump carries offsets in a different base with a different ASCII delimiter. They are displays, and plain hex is an encoding. The distinction decides the tool when the dump has to travel: piping a binary through email, a log, or a patch needs xxd -p, and reading it back needs xxd -r -p. The display forms are for looking. The decode leg alone was not timed separately tonight; the 2.6366 seconds is encode plus decode combined.

Checklist

  • Before reading bytes off a bare hexdump line, check the grouping: it prints two-byte words in native byte order, so a7 c8 reads as c8a7, and the swap is silent.
  • Before counting lines or grepping a default od or hexdump dump, pass -v: without it, repeated lines collapse to a single *, and 4,194,304 lines of zeros print as 3.
  • Before asserting a line count on a -v dump, remember the trailing offset line: od and hexdump print 4,194,305 lines for 4,194,304 groups, while xxd prints exactly 4,194,304.
  • Before piping a dump somewhere it has to come back from, use xxd -p: it is the fastest arm at 0.6848 seconds and the only reversible one, reproducing the source byte-identically in 2.6366 seconds for encode plus decode.
  • Before choosing between the two canonical forms on speed alone, check the table: hexdump -C costs 5.31 times xxd tonight and od -A x -t x1z costs 4.89 times, for the same visual output.
  • Before quoting a ratio, check the range: xxd rep 1 was 1.2990 seconds against a 1.2378 median tonight and 1.1733 the night before, so the same-format ratios moved from 5.38 to 5.31 and 4.99 to 4.89 while the ranking stayed.
  • Before reusing these numbers, check the setup: WSL2, 32 CPUs, xxd 2023-10-25, hexdump 2.39.3, od coreutils 9.4, tmpfs, warm page cache, one thread per arm, one 64 MiB random binary, sha256 5166398e….

Sources

  • xxd(1) manual page — read on the box 2026-11-10 (xxd 2023-10-25): creates a hex dump of a file or standard input and converts a hex dump back to its original binary form; -p outputs in plain hex dump style; -r -p reads plain hexadecimal dumps without line number information and without a particular column layout. No web copy of this manual page exists on man7.org (verified 404 on 2026-11-10); the box copy is the source.
  • Linux man-pages, hexdump(1) — read 2026-11-10: -C is canonical hex plus ASCII display; -v causes hexdump to display all input data, and without it identical groups of output lines are replaced with a single asterisk; the default display is very similar to the -x output, and the default format and the -x, -d, and -o options use multi-byte format units displayed in the system's native byte order, so single-byte formats such as -C are the byte-order independent choice (newer util-linux adds -X, one-byte hex; it is not in 2.39.3). Box runs util-linux 2.39.3.
  • Linux man-pages, od(1) — read 2026-11-10: -A x sets the output format for file offsets to hex; -v means do not use * to mark line suppression; adding a z suffix to any type displays printable characters at the end of each output line; the example od -A x -t x1z -v is given as display hexdump format output. Box runs GNU coreutils 9.4; the manual text is coreutils 9.11 and every cited behavior was exercised by the probe itself.
  • Nick Janetakis, Randomly Order Lines on the Command Line with sort or shuf — read 2026-11-10: publishes the closest measured table in the neighboring family, sort -R 6.65 seconds at 1M lines and 81 seconds at 10M against shuf 2.81 seconds at 10M, one run each. A different job, shuffling lines rather than dumping bytes, which is why that family was killed and this guide measures a different question.
  • Veldica, cmp vs diff: File Equality, Measured — the sibling guide: the same look-at-bytes family, an equality question rather than a display question. This guide dumps one file for reading; it does not compare two files.
  • Veldica, dd vs cp: File Copy by Block Size, Measured — the sibling guide: same 64 MiB corpus scale and tmpfs harness lineage, a copying question. This guide displays the bytes; it does not copy them.

Keep Exploring