the memory hierarchy
Imagine your desk while you study. The book open in front of you is reached instantly. A small pile of books at arm's reach takes a second to grab. The bookshelf across the room takes a walk. The public library across town takes a whole trip. You cannot keep every book on your desk — the desk is tiny — but you also cannot work if every book is at the library. So you arrange storage in layers: tiny and instant near you, huge and slow far away, with sensible middle layers in between. The memory hierarchy is exactly this arrangement for a computer's data.
From fastest and smallest to slowest and biggest, a typical hierarchy runs: registers (a few dozen words, inside the CPU, accessed in well under a nanosecond), then one or more cache levels (L1, L2, often L3 — kilobytes to tens of megabytes of fast SRAM), then main memory (gigabytes of DRAM, tens of nanoseconds away), then storage like an SSD or hard disk (terabytes, but thousands to millions of times slower). Each level down is roughly bigger, cheaper per byte, and slower. The hierarchy exists because no single memory technology is simultaneously fast, large, and cheap — you must trade one off against the others, so you stack several technologies and let each cover for the next.
The whole point is an illusion: the programmer is given the impression of one enormous memory that is also nearly as fast as the top level. That illusion only works because real programs touch a small, predictable slice of their data at any moment (the principle of locality), so keeping that slice in the fast upper levels serves most accesses quickly. The hierarchy is the single most important reason a modern computer's memory feels fast, and getting your data to live near the top of it is one of the biggest performance levers a programmer has.
Rough numbers on one machine: a register access ~0.3 ns, an L1 hit ~1 ns, an L2 hit ~4 ns, an L3 hit ~15 ns, a main-memory access ~80 ns, an SSD read ~50,000 ns. Reaching down one level can cost 5x to 1000x more time — which is why where your data lives matters enormously.
Each level down is bigger, cheaper per byte, and far slower; the hierarchy fakes one fast, huge memory.
The hierarchy gives an ILLUSION of speed, not a guarantee. If a program's accesses scatter unpredictably (poor locality), it keeps missing the fast levels and runs at near main-memory speed — same correct answer, many times slower.