Interactive lessons
Byte Stepper: Binary, UTF-8, Magic Numbers and Entropy, Step by Step
Four small tracers that show what happens to data one step at a time. Type a value, press play, and watch a number become bits, a word become bytes, a header give away its format and a run of bytes turn into an entropy score.
Steps
The Byte Stepper takes four ideas that every binary analysis guide assumes you already know and slows them down until each step is visible. Nothing is uploaded or stored: every calculation runs in your browser, and the log on the right keeps each step so you can jump back to the one that did not make sense. The arrow keys move one step at a time, and the speed button switches between half, normal and double speed.
Binary numbers: from decimal to bits
A byte holds eight bits, each worth a power of two from 1 up to 128, so one byte covers the whole numbers 0 to 255. The tracer converts a decimal number by repeated division. Each remainder of a division by 2 is the next bit, lowest first, and the quotient carries on to the next step. Take 77: the remainders are 1, 0, 1, 1, 0, 0, 1, 0, which gives 01001101 once read from the top bit down. Add the weights of the ones (64 + 8 + 4 + 1) and you are back at 77.
Hex is the same number in groups of four bits. 0100 is 4 and 1101 is 13, written D, so 77 is 0x4D. This is why hex editors are the default view for raw data: two hex digits always describe exactly one byte, and familiar values become easy to spot. 0x4D also happens to be the letter M in ASCII, which is the first byte of every Windows executable.
Text to bytes: ASCII and UTF-8 encoding
A file stores numbers, not letters. Every character first gets a code point from Unicode, and an encoding decides how that number is written as bytes. UTF-8, used by about 98% of web pages, keeps code points 0 to 127 in one byte, so plain English text looks the same in ASCII and in UTF-8. Above that, UTF-8 spreads the bits over two, three or four bytes and marks them so a reader can find character boundaries even in the middle of a stream.
| Character | Code point | UTF-8 bytes | Length |
|---|---|---|---|
| A | U+0041 | 41 | 1 byte |
| é | U+00E9 | C3 A9 | 2 bytes |
| € | U+20AC | E2 82 AC | 3 bytes |
| 𝄞 (G clef) | U+1D11E | F0 9D 84 9E | 4 bytes |
The first byte of a sequence starts with as many ones as the sequence has bytes, followed by a zero: 110 for two bytes, 1110 for three, 11110 for four. Every continuation byte starts with 10. In a hex dump this gives UTF-8 a recognisable texture: bytes in the C0 to F4 range followed by bytes in 80 to BF. Text in UTF-16 looks different again, with a zero byte after nearly every Latin letter, which is often the quickest way to tell the two apart at a glance.
Magic numbers: how a file reveals its format
Tools such as file and binwalk rarely trust a file extension. They read the first bytes and compare them with a list of known signatures, the magic numbers. The tracer does exactly that against ten common formats and crosses out each candidate the moment one byte disagrees. A PNG needs all eight of its signature bytes (89 50 4E 47 0D 0A 1A 0A), a gzip stream only two (1F 8B), and an ELF binary four (7F followed by the letters ELF).
Once the signature matches, the bytes after it stop being anonymous. In an ELF header byte 4 says whether the binary is 32 or 64-bit and byte 5 gives the byte order. In a ZIP local header bytes 8 and 9 name the compression method, where 8 means DEFLATE. The PNG signature is followed by the length and type of its first chunk, IHDR, which holds the width, height and colour type. Reading these fields is how analysts confirm a guess before spending time on the rest of the file.
Shannon entropy: measuring randomness in bytes
Entropy measures how unpredictable the next byte is. The tracer counts how often each byte value occurs, turns each count into a probability p, and adds up -p x log2(p) for every value. The result sits between 0 and 8 bits per byte. A run of one repeated letter scores 0 because nothing is surprising. The words hello world score 2.85, because a few letters repeat. Plain English over a long stretch settles near 4.5, x86 machine code around 6, and compressed or encrypted data between 7.9 and 8.0.
The tracer also shows the catch. With 16 bytes there can be at most 16 distinct values, so even a random-looking sample tops out at log2(16) = 4. That is why the entropy views in the visual guide slide a window of hundreds of bytes over a file, and why a high score alone cannot tell compression from encryption, as the compression vs encryption guide explains with real measurements.
Where to go after the basics
Each tracer covers the first move of a real analysis. Bits and hex let you read a hex dump; encodings tell you whether a region is text; signatures name the container; entropy points to the compressed or encrypted part. The next step is to see a whole file at once. Binary visualization explained shows how digram and trigram views turn those same bytes into pictures, and Veles puts the hex view, the entropy plot and the 3D views side by side for files of any size.
Questions readers ask
Why does the number to bits tracer divide by 2?
Dividing by 2 and keeping the remainder peels off the lowest bit each time. 77 gives remainders 1, 0, 1, 1, 0, 0, 1, 0, which read from the last one back to the first is 01001101, or 0x4D in hex. The same method works in any base: divide by 16 and you get hex digits directly.
Why does é take two bytes but A only one?
UTF-8 keeps every code point below 128 in a single byte, identical to ASCII, so A stays 0x41. Code point 233 (é) needs 8 significant bits, more than the 7 a single UTF-8 byte can hold, so it is split over two bytes: C3 A9. The euro sign takes three bytes (E2 82 AC) and most emoji take four.
Can a file lie about its magic number?
Yes. Magic bytes are a convention, not a guarantee: a polyglot file can start like a PDF and still be a valid ZIP, and malware often fakes a harmless header. Treat the signature as the first hypothesis, then confirm it by parsing the fields that follow, such as the PNG IHDR chunk or the ELF class byte.
Why does random-looking text only reach 4 bits per byte in the tracer?
With 16 bytes there can be at most 16 different values, so the maximum entropy is log2(16) = 4. Short samples always underestimate. That is why entropy tools slide a window of 256 bytes or more over a file: only then can a stream of ciphertext or compressed data reach the 7.9 to 8.0 range.
New to capture the flag? Formats, teams and a first-month plan in one place.
Read the CTF guide