Total-Bits Calculation
“How many total bits are required for a direct-mapped cache with … ?” is on every final. The data is only part of it — you also store a tag and a valid bit per line. Here's the reliable recipe.
1. The recipe
① Block size in bytes = (words/block) × 4
② Number of lines = data capacity ÷ block size
③ index = log₂(lines) · block offset = log₂(words/block) · byte offset = 2
④ tag = address bits − index − block offset − byte offset
⑤ bits/line = 1 (valid) + tag + (words/block × 32) · Total = lines × bits/line
2. Worked — Autumn 2025 Q3(b)
Direct-mapped, 64 KB of data, 8-word (32-byte) blocks, 32-bit address. Find total bits.
Q3bbigTotal bits (tag + valid + data) for a 64 KB, 8-word-block direct-mapped cache, 32-bit address.
3. Index size from block counts — Q3(c)
A common variant: “a direct-mapped cache has m blocks and memory has n blocks — find the index size.” The index just selects one of the cache lines:
e.g. cache blocks ⇒ index = 10 bits, regardless of .
4. Live calculator
Block size = 32 B · Lines = 2,048 (index 11 bits) · block offset 3 · byte offset 2
Tag = 32 − 11 − 3 − 2 = 16 bits
Bits/line = 1 + 16 + 256 = 273
Total = 2,048 × 273 = 559,104 bits(546 Kibits)
Tag = 32 − 11 − 3 − 2 = 16 bits
Bits/line = 1 + 16 + 256 = 273
Total = 2,048 × 273 = 559,104 bits(546 Kibits)
Don't forget the +1 valid bit per line and the tag — a very common mistake is to report only the data bits.
Section checklist
- lines = capacity ÷ block size; index = log₂(lines).
- tag = address − index − block offset − byte offset.
- total = lines × (1 + tag + data); data = words/block × 32.