Why Computers Use a Memory Hierarchy

Understanding why computers need multiple layers of memory from registers to storage, and the SRAM vs DRAM tradeoffs that make it necessary.

computer memory hierarchydram vs sram

Core Idea

Computers use a memory hierarchy because CPUs are far faster than memory, and fast memory is expensive. The hierarchy exists to hide memory latency while keeping systems affordable. When reading “latency” think delay—it helped me, assuming this can help anyone else reading this.

Computer Memory Hierarchy Diagram

Simple Analogy

If every thought required grabbing a book, thinking would grind to a halt. Computers work the same way.

The Memory Hierarchy Layers

Memory TypeSpeed (Latency)Typical SizeCost per GBVolatility
Registers~1 cycle (0.3 ns)Bytes$$$$Volatile
L1 Cache2-4 cycles (~1 ns)32-64 KB$$$$Volatile
L2 Cache10-20 cycles (~7 ns)256 KB-1 MB$$$Volatile
L3 Cache40-75 cycles (~20 ns)8-32 MB$$Volatile
RAM (DDR4)100-200 cycles (~100 ns)8-64 GB$ (~$5/GB)Volatile
SSD10,000-100,000 cycles (~150 µs)256 GB-4 TB$ (~$0.10/GB)Persistent
HDD1,000,000+ cycles (~10 ms)1-20 TB$ (~$0.02/GB)Persistent

Each layer exists to hide the slowness of the layer below it.

Why RAM Exists

Without RAM:

RAM keeps the CPU busy by holding the working set of code and data.

Why RAM Is Not Enough

Even RAM is too slow for the CPU.

To prevent the CPU from stalling:

Access Time in Human Scale

If we scaled computer operations to human time:

OperationActual LatencyHuman Scale*
L1 cache reference0.5 ns1 second
L2 cache reference7 ns14 seconds
Main memory reference100 ns3 minutes
SSD random read150 µs3.5 days
HDD seek10 ms8 months

*If L1 cache access = 1 second in human time

This shows why the CPU can’t simply wait for storage—it would be frozen for months in “CPU time.”

Why Lower Layers Cannot Replace Higher Ones

The closer memory is to the CPU:

SRAM vs DRAM: The Key Tradeoff

This is why cache is small and RAM is big:

FeatureSRAM (Cache)DRAM (RAM)
Speed1-10 ns50-100 ns
Transistors per bit6 transistors1 transistor + 1 capacitor
Cost per GBVery high (~$1000+)Low (~$5)
DensityLowHigh
Refresh neededNoYes (every 64ms)
Power consumptionHigher (static)Lower (dynamic)
PredictabilityConsistent latencyVariable (due to refresh)
Typical sizeKB to MBGB
Best forSpeed-critical (cache)Capacity (main memory)

SRAM (used for registers and cache)

That’s why cache is measured in MB, not GB.

DRAM (used for RAM)

DRAM accepts leakage and refresh overhead in exchange for scale.

Why DRAM Is Not Used for Cache

Cache must be fast every time, not just on average.

One-Sentence Summary

The memory hierarchy exists because CPUs are much faster than memory, and physics makes fast memory expensive.

Why This Matters for Modern Computing

AI and Machine Learning Workloads

Gaming and Real-Time Applications

Mental Model (For Recall)

What’s Next

As a next step, I’m starting to look at the physical materials that make DRAM, SRAM, and modern chips possible. Silicon—derived from quartz sand—along with advanced metals appears repeatedly. I plan to explore this more deeply in a future post.