Foundations — Set-associative and fully associative caches
Before you can read the parent note on set-associative and fully associative caches, you must own every symbol it throws at you. This page builds each one from nothing — plain words, then a picture, then why the topic needs it. Read top to bottom; each block only uses things defined above it.
0. The picture behind everything: memory as a giant ruler
Everything in this chapter lives on one idea: memory is one long line of numbered boxes, each box holding one byte (8 bits). The number of a box is its address.

- The book = main memory (huge, slow), millions of numbered boxes.
- The notebook = the cache (tiny, fast), only a handful of boxes.
- The whole game: copy a chunk of the book into the notebook so the CPU can read it quickly.
Keep this picture in your head. Every symbol below is a label on some part of it.
1. Bit, byte, and "how many things can this count?"
Why do we care? Because addresses are written in bits, and the number of bits tells us how many boxes we can name.
- bits patterns.
- bits patterns.
- bits billion — that is why a "32-bit address" can name about 4 GB of boxes.
2. The exponent and its undo:
We just used ("two multiplied by itself times"). The topic constantly needs the opposite question:
"I have things to name. How many bits do I need?"
That question is answered by ==== (log base 2).
Why this tool and not ordinary division or ordinary logarithm? Because hardware addresses are made of bits, and each bit is a doubling. Counting doublings is exactly what does — no other function answers "how many bit-switches?".
3. Hexadecimal — a shorthand for bits
Long strings of bits are painful. Hexadecimal ("hex") packs 4 bits into one symbol, using – then – for –. Hex numbers are written with a 0x prefix.

Why the topic needs it: addresses like 0x001A4C0 are just bit-strings in disguise. To split an address into pieces you convert hex bits, chop, and read.
4. The address, and cutting it into three pieces
The CPU asks for a byte by its address: a fixed-width bit number (here bits wide, = "address width"). The cache does not treat all bits equally — it slices the address into three named fields.

Read the slice from the picture, least-significant (rightmost) first, because the low bits change fastest as you walk along the ruler:
Why three pieces and not one? Because a cache slot must answer three separate questions: where inside the block? (offset), which shelf do I search? (index), is this really the block I wanted? (tag). Each question gets its own bits.
5. Block and block size
Why copy a whole bundle instead of one byte? Spatial locality — programs almost always use neighbouring boxes soon after, so grabbing the bundle saves future trips.
- = block size in bytes (e.g. ).
- Offset bits . With , : exactly enough to name any of the bytes inside.
6. Line, cache size , and total lines
- = total cache size in bytes.
- Total number of lines:
Why? Each line stores exactly bytes, and there are bytes of room, so lines fit. In the picture, cut the small notebook into equal shelves.
7. Sets , ways , and associativity
Now the star of the parent note. We group the lines into sets.

Why this formula? You have shelves; you bundle them at a time; the number of bundles is . Substitute to get .
Read the three cases straight off the picture:
| Name | Sets | A block may live in… | |
|---|---|---|---|
| direct-mapped | exactly 1 shelf | ||
| -way set-associative | any of slots in its set | ||
| fully associative | anywhere |
- Index bits — enough bits to pick one of the sets.
- When (fully associative), : no index field at all. That is why the parent's fully-associative address has only tag + offset.
The direct-mapped extreme is developed further in Direct-mapped caches; the miss-type payoff is the subject of Conflict misses vs capacity misses.
8. Comparator and "parallel"
Why it matters: an -way set needs comparators; a fully-associative cache of lines needs comparators. That growing pile of hardware is the price of associativity, and it drives the tradeoff table in the parent note.
9. Tag bits, assembled
Putting Sections 4–7 together gives the parent's master equation:
Prerequisite map
Related topics that build on these same foundations: Cache replacement policies, Cache performance metrics, Write policies, Cache coherence, Translation Lookaside Buffer (TLB). Prefer Hinglish? See 5.4.03 Set-associative and fully associative caches (Hinglish).
Equipment checklist
Cover the right side; can you answer each before revealing?