Intuition The one core idea
A cache is a small fast copy of a tiny slice of memory, and to find something in it fast we cut the memory address into three fields of bits — one to pick a row, one to check identity, one to pick a byte. Everything else on the parent page is just counting how many bits go into each field , and every symbol below exists only to help us count those bits.
Before you can read the parent note Cache lines, tags, index, offset , you must be fluent in a handful of tiny ideas. This page builds each one from nothing — no symbol is used before it is drawn.
Picture a row of light switches. Each switch is one bit.
counting explodes as powers of two
With 1 switch you can show 2 different patterns (0 , 1 ).
With 2 switches you get 4 patterns (00 , 01 , 10 , 11 ).
With 3 switches you get 8 . Every extra switch doubles the number of patterns.
So k switches name exactly 2 k different things.
This single fact — "k bits name 2 k things" — is the engine of the whole topic. Read it backwards and it becomes the tool we actually use: if I need to name N different things, how many switches do I need? That backwards question is what the next symbol answers.
2 k
2 k means "multiply 2 by itself k times". So 2 0 = 1 , 2 1 = 2 , 2 2 = 4 , 2 3 = 8 , 2 6 = 64 .
The little raised number k is called the exponent . On our switch picture, k = number of switches, and 2 k = number of distinct patterns they can show.
Recall Fill the table (self-test)
2 0 = 1 , 2 1 = 2 , 2 2 = 4 , 2 3 = 8 , 2 4 = 16 , 2 5 = 32 , 2 6 = 64 , 2 8 = 256 , 2 10 = 1024 .
Why the topic needs it Line sizes and set counts are always powers of two (B = 64 = 2 6 , S = 256 = 2 8 ), because they are counted by whole bit-fields.
Now the backwards question from Section 0.
log 2 N in plain words
log 2 N is the answer to: "2 raised to WHAT power gives N ?" It is the undo button of 2 k .
If 2 k = N , then log 2 N = k .
log 2 and not some other tool
We are literally counting switches. Section 0 said k switches name 2 k things. If someone hands us the number of things N and asks how many switches , we need the operation that turns 2 k back into k . That operation is log 2 . No other tool answers "how many bits to count to N ".
Worked example Read it off the picture
log 2 64 = 6 because 2 6 = 64 — you need 6 switches to name 64 bytes inside a line.
log 2 256 = 8 because 2 8 = 256 — 8 switches to name 256 sets.
log 2 N works for any N ."
Why it feels right: the button looks universal.
Reality here: log 2 N is a whole number only when N is a power of two. Caches are always powers of two on purpose, so we never hit a fraction. If you ever compute log 2 100 = 6.64... , you rounded a design that wasn't a real cache.
Why the topic needs it Every field width — offset = log 2 B , index = log 2 S — is a log 2 .
Addresses are long strings of bits. Writing 32 ones and zeros is painful, so we group them.
Definition Binary vs hexadecimal
Binary = the raw bits, e.g. 1110 1111.
A nibble = a group of 4 bits.
Hexadecimal ("hex") writes one nibble as one symbol 0 –9 then A –F (where A = 10 , ... , F = 15 ). The prefix ==0x== just announces "the following is hex".
So 0xF = 1111 = 15 , and 0x2F = 0010 1111.
Common mistake "One hex digit lines up with the field boundaries."
Why it feels right: hex digits are tidy 4 -bit blocks.
Why it bites you: the offset is 6 bits, which is not a multiple of 4 . So the index does not start on a hex boundary. This is exactly the 0xDEADBEEF trap on the parent page — you must think in bits , not nibbles, when slicing.
Why the topic needs it Addresses like 0xDEADBEEF are hex; you must expand them to bits to slice fields correctly.
A and address width n
Memory is byte-addressable : every single byte has its own house number, called its address A . If addresses are n bits wide, there are 2 n possible addresses — i.e. the machine can name 2 n bytes of memory.
A "32 -bit machine" means n = 32 , so 2 32 bytes ≈ 4 GB can be named.
Picture a very long street where every byte is one house, numbered 0 , 1 , 2 , … , 2 n − 1 .
Why the topic needs it The address is the raw material we chop into tag/index/offset. n is the total width we must account for: n = tag + index + offset .
The parent uses ⌊ A / B ⌋ without warning. Here is the picture.
Intuition Why dividing an address by
B gives a block number
A line/block is B consecutive bytes. Bytes 0.. B − 1 live in block 0 ; bytes B ..2 B − 1 in block 1 ; and so on. Asking "which block is byte A in?" is asking "how many whole groups of B fit below A ?" — that is exactly ⌊ A / B ⌋ .
Bonus: in binary, dividing by B = 2 offset is just deleting the low offset bits . That is why chopping bits = arithmetic for free, the whole reason hardware likes this scheme.
Why the topic needs it The low bits of the block number become the
index ; the leftover high bits become the
tag . See
Spatial and temporal locality for
why grouping bytes into blocks pays off.
Now the four cache dimensions, in build order.
Definition The cache symbols
B = bytes per line (block size), e.g. B = 64 . Sets the offset width = log 2 B .
L = total number of lines the whole cache holds.
w = ways = how many lines share one set (see Cache associativity & replacement policies ).
S = number of sets (rows) , and S = L / w . Sets the index width = log 2 S .
Intuition How they fit together
Think of the cache as a grid: S rows, each row holding w lines side-by-side. Total lines L = S × w . Rearrange: S = L / w . Direct-mapped is just w = 1 (so S = L ); fully associative is w = L (so S = 1 , zero index bits).
Why the topic needs it These four numbers, plugged into log 2 , produce every field width on the parent page.
You now own every piece. The parent's headline formula reads, symbol by symbol:
Read it as three "how many bits?" questions answered by log 2 , on an n -bit house number from §4.
bits = yes or no switches
k switches name two-to-the-k things
log base 2 = how many bits
group bits into nibbles = hex 0x
divide by B = drop low bits = block number
ADDRESS SPLIT tag index offset
Convert 2 6 to a plain number 64 .
Convert log 2 256 to a plain number 8 (because 2 8 = 256 ).
Why must B and S be powers of two? So each field is a whole number of bits (log 2 is an integer only for powers of two).
Expand the hex digit 0xF to 4 bits 1111.
What does the prefix 0x announce? The number that follows is written in hexadecimal.
What does n mean, and how many bytes can it name? Address width in bits; it names 2 n bytes.
What does ⌊ A / B ⌋ compute, in words? The block number — how many whole B -byte lines fit below address A .
In binary, dividing by B = 2 k is the same as… Deleting the low k bits.
Relate S , L , w S = L / w (sets equal total lines divided by ways).
How many index bits when S = 1 (fully associative)? Zero, since log 2 1 = 0 .
Offset width formula and what it depends on log 2 B ; depends only on line size, not total cache size.
Tag width formula n − log 2 S − log 2 B (the leftover bits).