Files and data: everything is bits
Inside a computer, every number, letter, photo and song is stored as bits: zeros and ones. Watch eight bits become a byte and a number, see how the same byte can be a letter (ASCII and UTF-8) or part of a pixel's colour, and find out what a file really is, what its extension does, and what kB, MB and GB measure.
5 quick questions
Pick an answer to see why. Your score saves with your progress.
01How many different values can one byte (8 bits) hold?
Each of the 8 bits doubles the number of patterns: 2 × 2 × 2 × 2 × 2 × 2 × 2 × 2 = 256. That is why a byte holds a number from 0 to 255: 256 values, counting 0.
02Using the place values 128, 64, 32, 16, 8, 4, 2, 1, what number is the byte 00000101?
Only the places for 4 and 1 hold a 1, so the byte is 4 + 1 = 5.
03In UTF-8, how many bytes does the letter é take?
UTF-8 uses 1 to 4 bytes per character. The 128 ASCII characters, such as A, take one byte; é takes two, 195 169 (C3 A9 in hexadecimal); most emoji take four.
04A file holds the three bytes 72, 105, 33. What are they?
Bytes do not say what they mean. A text editor reads them as ASCII text (Hi!), an image program could read them as one pixel's red, green and blue, and a calculator just sees three numbers.
05You rename photo.png to photo.txt. What happens to the bytes inside the file?
The extension is only a hint about how to read the bytes. Renaming does not change a single byte, but a text editor opening photo.txt will show gibberish, because those bytes are pixel data, not text.
Glossary
- Bit
- The smallest piece of data a computer stores: a 0 or a 1.
- Byte
- Eight bits in a row. One byte has 256 patterns, so it can hold a whole number from 0 to 255.
- Binary
- Counting with only the digits 0 and 1. Each place is worth twice the one to its right: 1, 2, 4, 8, 16, 32, 64, 128.
- Hexadecimal
- Counting in base 16 with the digits 0-9 and A-F. Programmers write each byte as two hex digits: 65 is 41, 255 is FF.
- ASCII
- An old table that gives 128 characters (English letters, digits, signs and control codes) the numbers 0 to 127. A is 65.
- Unicode and UTF-8
- Unicode gives every character in every writing system, and every emoji, a number called a code point. UTF-8 is the most common way to store those numbers as 1 to 4 bytes.
- Pixel
- One tiny coloured square of a picture, usually stored as three bytes: red, green and blue, each 0 to 255.
- File and extension
- A file is a named sequence of bytes kept on a disk. The extension, the end of its name such as .txt or .png, tells programs how to read the bytes.
Notes and sources
- A byte has been 8 bits on practically every computer since the 1970s. Standards that need to be exact call an 8-bit byte an octet.
- ASCII (first published in 1963) defines 128 codes, 0 to 127: 95 printable characters, from space (32) to ~ (126), and 33 control codes such as newline (10).
- Unicode 17.0 (2025) defines 159,801 characters; code points run from U+0000 to U+10FFFF. UTF-8 stores the first 128 code points as the same single bytes as ASCII, so plain ASCII text is already valid UTF-8 (RFC 3629).
- Hexadecimal (base 16) writes each byte as exactly two digits from 0-9 and A-F: 65 is 41, 255 is FF. Programmers use it because it is short and maps neatly onto bits (each digit is 4 bits).
- Many image formats store 3 bytes per pixel (24-bit colour). Some add a fourth byte, alpha, for transparency; a web page's ImageData holds 4 bytes per pixel in RGBA order.
- Most image files are compressed. A PNG or JPEG of a 1920 × 1080 photo is usually far smaller than the 6,220,800 bytes of raw pixels.
- Some programs count 1 KB as 1,024 bytes. The standard names for powers of 1,024 are the binary prefixes KiB, MiB and GiB: 1 KiB = 1,024 bytes, 1 MiB = 1,048,576 bytes.
- The extension is only a convention. Many formats also begin with a fixed signature: every PNG file starts with the same 8 bytes, 137 80 78 71 13 10 26 10, and the 2nd to 4th spell PNG in ASCII.
- Python library: Binary sequence types (bytes)
- Python HOWTO: Unicode
- Python library: Built-in functions (int, bin, ord, chr, open)
- RFC 20: ASCII format for network interchange
- RFC 3629: UTF-8, a transformation format of ISO 10646
- Unicode FAQ: UTF-8, UTF-16, UTF-32 and BOM
- Unicode 17.0.0
- MDN: rgb() colour values
- MDN: ImageData (RGBA bytes of an image)
- NIST: Prefixes for binary multiples
- W3C: PNG specification, file signature
- Python library: mimetypes
Quiz Unlocks after the last step.