Bytes as coordinates

Binary Visualization Explained: Digram, Layered Digram and Trigram Views

Digram visualization and its cousins follow one idea: take neighboring bytes, use them as coordinates, and count. The details decide what you can see, so this page builds each view from a four-byte example up to a real 1.4 MB executable.

Hexfield editorial

Turn a file around in 3D.

Every three neighbouring bytes become one point in a 256 x 256 x 256 cube. Drag the cube to rotate it: the shape of the cloud tells you what kind of data you are looking at.

x: byte ny: byte n+1z: byte n+2

ls.elf

Triples drawn
-
Distinct triples
-
Unique share
-

Program code. Over a third of all triples contain a 00 byte, so the points stack up on the three faces that meet at the zero corner, while recurring instruction patterns cut bars through the middle.

Colour follows the position in the file: violet at the start, pink in the middle, lime at the end. Drag or use the arrow keys to turn the cube.

GNU Bash 5.2 ELF, 1,446,024 bytesSample file
51,175 of 65,536Distinct digrams
252,496 of 16,777,216Distinct trigrams
about 5,648 bytes per 1/256Layer size
Digram plot of a 64-bit x86 ELF on a 256 by 256 grid, bright along the zero row and column with clusters around 0x48
Digram of the Bash ELF: the zero row and column dominate, and the cluster at 0x48 marks REX-prefixed x86-64 instructions.

Binary visualization explained in one sentence: treat consecutive bytes of a file as coordinates and plot how often each coordinate occurs. It does not matter whether the input is an executable, a photo or a disk image, since from this point of view every file is only a sequence of values from 0 to 255. The views differ in how many bytes form one point and in what extra dimension is added. This page works through digram visualization, the layered digram and the trigram, then covers color, sampling and the minimap that real tools add on top. Figures come from one reference file, the GNU Bash 5.2 ELF for x86-64, which is 1,446,024 bytes long with an overall entropy of 6.20 bits per byte.

Digram

A digram is a pair of adjacent bytes. Take a tiny file of four bytes, 02 03 05 01. Sliding a two-byte window across it gives three pairs: (2, 3), (3, 5) and (5, 1). Each pair becomes a point on a 256 by 256 plane, the first byte on the x axis and the second on the y axis. Every byte except the first and the last is used twice, once as x and once as y.

A real file produces one digram per byte, minus one. For Bash that is 1,446,023 pairs falling into 65,536 possible cells. Brightness encodes frequency, usually on a log scale, because the distribution is extremely skewed: the pair 00 00 alone occurs 204,149 times, FF FF 34,202 times, and the x86-64 pairs 48 89 and 48 8D around 14,000 and 13,000 times each. Of the 65,536 cells, 51,175 are hit at least once, so the plane is 78% populated, yet the brightness is concentrated in a few rows and columns.

Reading a digram visualization comes down to a few shapes. A bright row and column at zero mean padding, small integers or wide characters. A dense square between 0x20 and 0x7E means ASCII text. A uniform gray field means compressed or encrypted data. Diagonal streaks often mean arithmetic sequences such as offset tables, where each value is the previous one plus a constant.

Layered digram

A single digram mixes the whole file into one picture, so a ZIP central directory at the end and the compressed body in front land on the same plane. The layered digram fixes that by splitting the file into 256 slices of equal size and computing one digram per slice. The slices are stacked along a third axis, giving a cube whose height is file position.

For Bash each layer covers about 5,648 bytes. Layers that cross .text show the code fingerprint, the layers over .rodata turn into the ASCII square, and the final layers over the symbol and string tables look different again. A layered digram is the quickest way to see where a format changes, and it is the view that makes a block of headers at the end of a compressed file stand out as a lit band on top of uniform noise.

Trigram: three bytes as one point

The trigram view extends the digram to three adjacent bytes, plotted as a point in a 256 by 256 by 256 cube. Every byte is used three times: once as x, once as y, once as z. The cube has 16,777,216 cells, and Bash, with roughly 1.44 million trigrams, touches only 252,496 of them, or about 1.5%. That sparsity is the reason trigram views look like clouds with clear structure, where the same file as a digram is a crowded plane. The 3D cloud near the top of this page draws exactly this view from six sample files, and from any file you open, so you can turn the cube and compare the shapes yourself.

The x86-64 fingerprint shows best here. Instructions working on 64-bit registers carry a REX prefix from 0x40 to 0x4F, mostly 0x48 (REX.W), followed by an opcode such as 0x89 or 0x8B for MOV or 0x8D for LEA. Triples that end in such a pair form one bar along a face of the cube, and triples that start with it form a second bar. Two parallel bars therefore point to 64-bit x86 code before any disassembler has run. The binary data visualization overview shows how other formats, from ARM32 code to PNG, look in the same views.

Compression algorithms leave weaker traces in trigram clouds, visible only after rotating the cube, and those traces are the basis of the guide on recognizing compressed and encrypted data.

Binary visualization extras explained

Pure frequency would give grayscale images. Veles, an open source tool built around these views, tinted each point by position: yellow for digrams or trigrams found mainly near the start of the file, blue for those found mainly near the end, white for those spread evenly or concentrated in the middle. That single extra channel tells you whether a cluster belongs to a header or a trailer without switching views.

The trigram and layered digram cubes can also be redrawn as a cylinder or a sphere. The data does not change. Each point still has three values, and switching from Cartesian to cylindrical or spherical coordinates only bends the space, which sometimes separates clusters that overlap in the cube.

Sampling and the minimap

Counting every trigram of a multi-gigabyte image is slow, and drawing millions of points is slower, so any binary visualization tool meant for large inputs samples them. Veles took a sample size N, usually 1 to 10 MB, and picked the square root of N runs of the square root of N bytes each. For a 1 MB sample that is 1,024 runs of 1,024 bytes: enough runs to cover the whole file, each long enough to keep real byte sequences intact. The cost is that structures smaller than a run can be missed, so narrow the range before drawing conclusions about small features.

The minimap is the companion strip that shows the whole file as a grid of texels, one per equal-sized part. In the default mode each texel is the average byte value of its part; in the alternative mode it is the Shannon entropy. Two sliders choose which range the main view draws, and stacking several minimaps narrows a large file down to a few hundred bytes. The Veles tool page covers installation and a full session.

The whole approach goes back to Christopher Domas’s cantor.dust talk at DerbyCon 2012, which introduced digram and trigram views to reverse engineering. With binary visualization explained this far, the remaining skill is practice: open known files, learn their shapes, then compare unknown ones against that mental library.

Questions readers ask

Why are digram plots usually drawn on a log scale?

Counts are extremely uneven. In the Bash ELF the pair 00 00 occurs 204,149 times while most pairs occur a handful of times. A linear scale would show one white dot and black everywhere else. A logarithmic brightness keeps rare pairs visible, which matters because rare pairs often belong to the small, interesting regions such as headers and tables.

Does the order of the two bytes matter in a digram?

Yes. The pair 48 89 is a different point from 89 48. That asymmetry is what makes architecture fingerprints possible: x86-64 code produces many 48 89 and 48 8B pairs but far fewer reversed ones. A plot that is symmetric around its diagonal points toward data with little sequential structure.

What is the difference between a digram and a trigram view?

A digram takes two neighbouring bytes and draws them as one point on a flat 256 by 256 grid. A trigram takes three and places the point in a 256 by 256 by 256 cube, so it needs a 3D view you can rotate. The extra byte separates data that look alike on the flat grid: patterns that overlap in two dimensions often pull apart into separate bars and planes in three.

How large does a file need to be for a readable digram?

The grid has 65,536 cells, so a small file leaves most of them empty. The plain text sample on this page is 11,358 bytes and fills only 666 cells, yet that is already enough to see that it is text, because all of them sit in the letter range. Finer structure, such as the instruction patterns of machine code, needs many more pairs than cells: the 142,312-byte Linux program sample fills 15,574 cells and shows clear lines.

Why does encrypted data look the same in every view?

Good encryption makes every byte value equally likely and independent of its neighbours, so no pair or triple is preferred. In the encrypted sample on this page, 58,104 of the 65,536 digram cells are filled, almost exactly what pure chance predicts for that many pairs, and 99.6% of all byte triples occur only once. The result is an even fog with no lines, faces or clusters.

Can I try the trigram view on my own file?

Yes. The 3D cloud near the top of this page reads a file you open in your browser and draws its trigrams, without uploading anything. Files larger than 8 MB are cut to their first 8 MB, and very long files are sampled evenly so the cube stays smooth to rotate.

Can I build these views without special software?

Yes. A digram is a 256 by 256 array of counters; a few lines of Python with NumPy fill it from a file and save it as an image with a log scale. Trigrams need a 3D scatter plot instead of an image. Dedicated tools add sampling, interactive rotation and links back to file offsets.

New to capture the flag? Formats, teams and a first-month plan in one place.

Read the CTF guide