---
title: "How a processor's cache works: three levels of small, fast memory between the core and the RAM"
canonical: "https://rawy.si/preview/cbbc790c-3078-488b-b58b-99bf2f888899/article/how-a-cpu-cache-works-levels-lines-and-misses"
url: "https://rawy.si/preview/cbbc790c-3078-488b-b58b-99bf2f888899/article/how-a-cpu-cache-works-levels-lines-and-misses"
author: "The Signal Review desk"
author_url: "https://rawy.si/preview/cbbc790c-3078-488b-b58b-99bf2f888899/author/signal-review-desk"
published: 2026-10-01T09:50:56.586Z
modified: 2026-10-03T23:17:51.864Z
section: "Computing"
tags: ["Explainer"]
language: en
license: "© Signal Review. All rights reserved. Quotation of short passages with attribution and a link to the source is permitted."
---

# How a processor's cache works: three levels of small, fast memory between the core and the RAM

*Why a chip keeps copies of what it just used, and what happens when the copy is not there*

> A modern processor spends most of its time waiting for memory. The cache is the answer: a hierarchy of small, fast stores that hold copies of the data a core has touched recently, so that the next access takes a few cycles instead of a few hundred.

## Key points

- A cache is a small, fast memory between a processor core and the RAM that keeps copies of recently used data and instructions.
- Caches fetch memory in fixed blocks called cache lines, 64 bytes on current Intel and AMD processors.
- Intel's optimisation manual gives its recent cores a 48-kilobyte level 1 data cache and a level 2 cache of one to two megabytes per core.
- A level 1 hit returns data in about four or five cycles; a miss goes down to level 2, then level 3 and finally to the RAM.
- Coherence protocols such as MESI invalidate other cores' copies of a line before a write, so that every core sees one consistent memory.

![How a processor's cache works: three levels of small, fast memory between the core and the RAM](https://rawy.si/uploads/cbbc790c-3078-488b-b58b-99bf2f888899/images/photo-cpu-die.jpg)

A **cache** is a small memory placed between a processor core and the main memory (the RAM) that keeps copies of recently used data and instructions. It exists because of a gap that has widened for forty years: a core can execute an instruction in well under a nanosecond, while a trip to main memory takes tens of nanoseconds.

Without a cache, the core would spend nearly all of its time idle, waiting for bytes to arrive. With one, most of the accesses a program makes are served in a handful of cycles.

The principle behind it is **locality**. Programs tend to reuse the same data soon after they touch it (temporal locality) and to use data stored next to what they just used (spatial locality). A cache exploits both by fetching memory not one byte at a time but in fixed blocks called **cache lines**, 64 bytes on the current Intel and AMD processors according to both companies' optimisation manuals, and by keeping those lines around until the space is needed for something newer.

## Why does a processor have three levels of cache?

Modern designs stack several caches. The **level 1** cache is the smallest and closest to the core, and is usually split into an instruction cache and a data cache; the **level 2** cache is larger and slower; the **level 3** cache is larger again and is commonly shared between all [the cores on a die](/article/how-a-silicon-wafer-is-grown-from-one-seed-crystal). Intel's optimisation reference manual gives, for its recent core designs, a level 1 data cache of 48 kilobytes and a level 2 cache of one to two megabytes per core, while the level 3 cache runs to tens of megabytes across a chip. Each level trades size for speed: the bigger the array, the longer the wires and the more cycles a lookup takes.

When the core asks for an address, the level 1 cache checks whether it holds the line. If it does, that is a **hit**, and the data is returned in about four or five cycles. If not, a **miss**, the request goes down to level 2, then level 3, and finally to the memory controller and the RAM. Each step costs more. The line that comes back is written into every level on the way up, and some older line has to be evicted to make room. Which line goes is decided by a **replacement policy**; the classic choice is to drop the line that was least recently used, though real processors use cheaper approximations of that rule.

## Keeping the copies honest

The copies bring a problem of their own. When one core writes to a line that another core also holds, [the other copy is stale](/article/how-the-domain-name-system-turns-a-name-into-an-address). The processors solve this with a **coherence protocol**, most commonly a variant of MESI, whose letters stand for the states a line can be in: modified, exclusive, shared or invalid. A write forces the other copies to be invalidated before it can proceed, so that every core sees a single consistent memory. The traffic this generates is one reason why programs that share data across many cores can slow down rather than speed up.

The cache is invisible to a correct program: the code reads and writes addresses and never mentions it. But it is very visible to a program's speed. Walking through an array in order is fast because each line brought in serves the next fifteen accesses; jumping around a large structure at random is slow because almost every access misses. Much of performance engineering is, in the end, the art of keeping the working set inside the cache.

## Frequently asked questions

### Why does a processor need a cache?

Because a core can execute an instruction in well under a nanosecond, while a trip to main memory takes tens of nanoseconds. Without a cache the core would sit idle most of the time waiting for data; with one, most memory accesses are served in a handful of cycles.

### What is a cache line?

A cache line is the fixed block in which a cache fetches and keeps memory: 64 bytes on current Intel and AMD processors. Fetching whole lines exploits spatial locality, since programs tend to use data stored next to what they have just used.

### What is the difference between a cache hit and a cache miss?

A hit means the level 1 cache already holds the requested line, and the data comes back in about four or five cycles. A miss sends the request down to level 2, then level 3, and finally to the memory controller and the RAM, each step costing more time.

### Why can sharing data between cores slow a program down?

When one core writes to a line that other cores also hold, a coherence protocol such as MESI must invalidate their copies before the write can proceed. The traffic this generates is one reason programs that share data across many cores can slow down rather than speed up.

## Sources

- [Intel 64 and IA-32 Architectures Optimization Reference Manual](https://www.intel.com/content/www/us/en/content-details/671488/intel-64-and-ia-32-architectures-optimization-reference-manual-volume-1.html) — Intel Corporation
- [Computer Architecture: A Quantitative Approach, 6th edition, J. L. Hennessy and D. A. Patterson](https://shop.elsevier.com/books/computer-architecture/hennessy/978-0-12-811905-1) — Morgan Kaufmann (Elsevier)
