How Data Is Stored
Numbers, text, images, sound โ all of it becomes bits by agreeing on a code. Understanding these encodings demystifies how a computer holds everything from a letter to a movie.
If everything is bits, how does the same machine hold a number, a paragraph, a photo and a song? The answer is encoding: we agree on a code that maps each kind of thing to a pattern of bits. Bits have no meaning on their own - the code gives them meaning. This session walks through how the main types of data get stored, and what 'memory' actually is.
Text, numbers, images, sound
Each kind of data has an agreed code that turns it into bits - and back again.
| Data | How it's encoded |
|---|---|
| Whole numbers | Directly in binary (see larzbase) |
| Text | Each character -> a number (ASCII / Unicode) |
| Images | A grid of pixels, each a red/green/blue number |
| Sound | The wave's height sampled thousands of times/sec |
Text is a great example: 'A' is agreed to be 65, 'B' 66, and so on (the ASCII code), and Unicode extends this to every language and emoji. A photo is millions of colour-numbers; a song is thousands of height-numbers. All just numbers, all just bits.
The same bits can mean different things
Because meaning comes from the code, the very same bits mean different things in different contexts - which is why file formats matter.
01000001 is 65, or 'A', or a shade of colour - it depends entirely on what the program has been told the bits represent. That's what a file's format (and its extension, like .txt or .jpg) is for: it says 'read these bits this way'. Open a photo in a text editor and you see gibberish - not because the data is broken, but because you're applying the wrong code. Encoding is a shared agreement, nothing more.Memory: where the bits live
All these bits have to be kept somewhere. Broadly, there are two places, with a key trade-off.
| Kind | Speed | Keeps data when power off? |
|---|---|---|
| Memory (RAM) | Very fast | No - it's forgotten |
| Storage (disk/SSD) | Slower | Yes - it persists |
RAM is the fast workspace the computer uses while running (and it empties when you switch off - which is why unsaved work vanishes). Disk/SSD is slower but permanent. This is exactly why programs 'save' to files - moving data from fleeting memory to lasting storage.
Everything is an encoded number
- Encoding maps each kind of data to bits by an agreed code.
- Text = characters as numbers (ASCII/Unicode); images = pixel colour-numbers; sound = sampled heights.
- Format tells the computer which code to read the bits with.
- RAM is fast but forgotten on power-off; disk is slower but permanent.
๐ฏ Key takeaways
- Encoding maps each kind of data (text, images, sound) to bits via an agreed code.
- Text uses ASCII/Unicode (each character is a number); images are pixel colour-numbers; sound is sampled heights.
- The same bits mean different things by context - a file's format says which code to use.
- RAM is the fast workspace but forgotten on power-off; disk/SSD is slower but permanent (why we 'save').
Frequently asked
What's the real difference between memory (RAM) and storage (disk)?
They're both places to keep bits, but they serve different roles with a key trade-off. RAM (memory) is the computer's fast working space - where the program and the data it's actively using live while the computer is on. It's very fast, which the processor needs to keep up, but it's volatile: cut the power and everything in RAM is gone instantly. Storage (a hard disk or SSD) is slower but non-volatile - it keeps your files whether the power's on or not. That's why the two exist together: RAM gives the speed needed to run things, storage gives the permanence needed to keep them. It's also why unsaved work disappears if your computer suddenly loses power - it was only in RAM. 'Saving' a file means copying data from fast-but-temporary RAM to slow-but-permanent storage, and 'opening' a file does the reverse. Understanding this makes a lot of computer behaviour - saving, loading, why more RAM helps with running many things - suddenly make sense.
Why does opening a photo in a text editor show gibberish?
Because you're applying the wrong code to the bits. A photo file is a pattern of bits meant to be read as image data - pixel colours, encoded in a specific format like JPEG. A text editor, though, reads bits using a text code (like ASCII/Unicode), interpreting each byte as a character. When it applies that text code to bits that were actually encoding colours, it produces meaningless characters - the gibberish you see. The bits aren't broken and the file isn't corrupt; the editor is just reading them the wrong way, like trying to read French with Spanish pronunciation rules. This is the whole point about encoding: bits carry no inherent meaning, and it's the format and the program's interpretation that give them meaning. It's why file formats and extensions matter - they tell software which code to use so the bits are read correctly. Open that same photo in an image viewer, which knows to apply the image code, and it appears perfectly.
Related lessons
Everything Is Bits
At the very bottom, a computer is millions of tiny switches that are either on or off. Eveโฆ
How Computers WorkWhat a CPU Actually Does
The CPU is the computer's engine โ and what it does is surprisingly humble: fetch a tiny iโฆ
Intermediate PythonWorking with Files
Real programs read and write files โ save data, load it back, process a document. It's simโฆ