Bits and bytes
A bit is the smallest piece of data a computer stores: a 0 or a 1, like a switch that is off or on. Numbers, words, photos and music are all stored as long rows of bits.
Eight bits side by side make a byte. Each bit doubles the choices: 2, 4, 8, ... up to 256 patterns for eight bits. So one byte can hold any whole number from 0 (all off) to 255 (all on).
Give each bit a place value: 128, 64, 32, 16, 8, 4, 2, 1. Add the places holding a 1: 64 + 1 = 65. This counting system is binary. Memory is a row of numbered byte boxes; this byte goes in box 0.
Text and pictures
Letters are stored as numbers. A table called ASCII gives each English letter, digit and sign a number: A is 65, B is 66, a is 97, space is 32. So byte 65, read as text, is the letter A.
ASCII has 128 characters. Unicode gives a number to over 150,000 characters from every script, plus emoji. UTF-8 stores each in 1 to 4 bytes: A takes one, é two (195 169), an emoji four. Tags show each byte in hexadecimal (base 16).
A picture is a grid of tiny coloured squares called pixels. Each pixel is usually three bytes: how much red, green and blue light to mix, each 0 to 255. This red pixel is 230, 57, 70.
Files
A file is a named row of bytes kept on a disk, so it survives when the power goes off. hi.txt holds exactly three bytes: 72, 105, 33. Opening the file copies them into memory.
Bytes do not say what they mean. 72, 105, 33 are three numbers. Read as ASCII text, they spell Hi!. Read as one pixel, they are a dark olive green. Only the program reading them decides.
The end of a file name, like .txt, is its extension. It tells programs how to read the bytes: .txt as text, .png as a picture, .mp3 as sound. Renaming a file changes no bytes, only the hint.
Sizes count bytes: a kilobyte (kB) is 1,000, a megabyte (MB) a million, a gigabyte (GB) a billion. hi.txt is 3 bytes. This 7 × 6 heart is 42 pixels × 3 = 126 bytes. An uncompressed 1920 × 1080 photo is about 6.2 MB.
Try it in the Python prompt
;; step 1/10 · Bits: 0 or 1 >>> 0b1, 0b0 # one bit: 1 or 0 (1, 0) >>> 2 ** 1 # so one bit has 2 patterns 2
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). 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.