Direct-Mapped vs Set-Associative vs Fully Associative Cache
Updated: November 11, 2026
A cache must decide where each block of memory may be stored. In a direct-mapped cache each block has exactly one possible line, which is simple and fast but suffers conflicts when two blocks share a line. In a fully associative cache a block can go anywhere, which avoids conflicts but needs a comparison against every line. A set-associative cache is the compromise: a block can go in any of a few ways within one set. Most CPU caches are set-associative.
Aspect
Direct-mapped
Set-associative
Fully associative
Where a block can go
Exactly one line, chosen by the index bits
Any of the ways (for example 4 or 8) in one set
Any line in the cache
Tag comparisons per access
One
One per way (for example 8)
All lines at once, in parallel
Hit time
Fastest
Slightly slower
Slowest
Hardware cost and power
Lowest
Moderate
Highest: a comparator for every line
Conflict misses
Most frequent
Reduced as the number of ways grows
None: only compulsory and capacity misses remain
Replacement policy
Not needed: only one choice
Chosen within the set (LRU or approximations)
Chosen among all lines
Typical uses
Small, simple caches and some microcontrollers
L1, L2 and L3 caches in most CPUs, usually 4 to 16 ways
Small structures such as TLBs and victim caches
Figures are typical orders of magnitude and vary by process generation and product.
When to use which
Direct-mapped
When simplicity, low power and speed matter more than hit rate.
Set-associative
The practical choice for most caches, since a few ways remove most conflict misses at modest cost.
Fully associative
For very small structures where the hit rate is critical and the comparison cost is affordable.
FAQ
What is a conflict miss?
A miss that happens because two blocks map to the same place even though other cache lines are free. Direct-mapped caches suffer most, and fully associative caches have none.
How many tags does an 8-way cache compare per access?
Eight, one for each way of the selected set.
Why are most CPU caches set-associative?
A few ways remove most conflict misses at a modest cost, while a fully associative cache needs a comparator for every line.
Where is a fully associative cache used?
In small structures such as TLBs and victim caches, where the hit rate matters most and the comparison cost is affordable.
A 64-byte line = 2⁶, so the offset is 6 bits. The number of lines is, and in a direct-mapped cache each line is its own set, so the index is 9 bits. The rest is the tag: 32 − 9 − 6 = 17 bits. 19 bits would apply to a 4-way set-associative cache, where the index shrinks by 2 bits, not to a direct-mapped one.
The number of lines is. A 4-way cache holds four lines per set, so there aresets, giving a 7-bit index and a 32 − 7 − 6 = 19-bit tag. 512 is the line count itself, which equals the set count only when direct-mapped. Raising associativity reduces the number of sets, which adds tag bits and comparators. 32 comes from dividing the 128 sets by the four ways a second time.
In a fully associative cache any data can go anywhere, so the whole cache is a single set. No set needs to be selected, so the index is 0 bits; the address splits into just offset and tag, and every access compares against all tags. That requires many comparators, so it does not suit large caches and is used for small structures such as TLBs. The line size determines the offset width, not the index.
A cache organization in which each address can be placed in exactly one location. It is simple with short hit time, but prone to conflict misses when addresses compete for the same slot.
A cache organization in which data can go in any of several locations (ways) within the one set selected by the address. An n-way cache compares n tags in parallel on each access.
A cache organization in which any data can be placed in any location. It has no conflict misses but must compare against every tag, so it suits small structures such as TLBs rather than large caches.
The unit in which data moves between a cache and the level below, also called a cache block. Many CPUs use 64 bytes, and the low address bits give the position (offset) within the line.
This page was drafted with AI and fact-checked by a separate AI review before publication. Our Editorial policy explains how we write and check content. If you spot an error, please tell us on our Contact page.