Why CPUs have L1, L2 and L3 caches
By TechCompare · Updated · How we check
Design your data for cache locality. It explains why array-of-structs vs struct-of-arrays matters, why linked lists are slow, and why cache-friendly code can run an order of magnitude faster.
Calculator
Memory & Storage Throughput Visualizer
Data to transfer: 1.0 TB
CPU cores execute instructions in fractions of a nanosecond. RAM responds in 50-80 nanoseconds. Without cache, every RAM access would leave a core waiting about 200 to 320 cycles at 4 GHz. The cache hierarchy (L1, L2, L3) bridges this gap by keeping frequently accessed data closer to the execution units. Each level is larger but slower than the one before it.
How this is calculated
The hierarchy works on the principle of locality: if a program accesses a memory address, it's likely to access nearby addresses soon (spatial locality) and the same address again soon (temporal locality). L1 caches the most recently used data at the smallest granularity (64-byte cache lines). L2 catches L1 evictions. L3 catches L2 evictions and is a shared pool for inter-core communication. See what L3 cache is for its size and speed.
Cache design is a trade-off between latency (smaller is faster), hit rate (larger catches more), and power consumption (larger uses more). Modern CPUs spend roughly 30-40% of their die area on cache.
Verdict
Lay out your data for locality, because the whole stack only helps when accesses stay close together. L1 caches recent data in 64-byte lines, L2 catches L1 evictions per core, and L3 pools L2 evictions across cores for inter-core sharing. Larger caches catch more but cost more latency and power, and modern CPUs still spend roughly 30-40% of die area on them.
More Latency scenarios
Related guides
Frequently asked questions
Why do CPUs have three levels of cache?
What is a cache line?
Why are linked lists slow on modern CPUs?
Related tools
RAM Latency Calculator
Convert DDR3/DDR4/DDR5 timings (CL, tRCD, tRP, tRAS) into true latency in nanoseconds.
Use toolRAID Calculator
Calculate usable capacity and fault tolerance for RAID 0, 1, 5, 6, and 10.
Use toolDisplay Bandwidth Calculator
Check display bandwidth for HDMI, DisplayPort, USB-C, Thunderbolt, and USB4.
Use tool