CPU Cache Address Tool

Cache Set Index Calculator

Enter a memory address and cache geometry to calculate its cache set index, cache-line number, block offset, tag, and exact address-bit breakdown for a power-of-two set-associative cache.

Set index Block offset Cache tag
Calculate Cache Address Fields
64 sets
Cache size, line size, associativity, and number of sets must form a valid power-of-two cache geometry.
Cache Set Index 13 Set 13 of 64
Cache Tag 0x9 Tag value above index and offset bits
Block Offset 5
Cache Line Number 1,165
Index Bits 6 bits
Offset Bits 6 bits
Address field breakdown
Address = Tag | Set Index | Block Offset
Cache Addressing

What Is a Cache Set Index?

A cache set index identifies which cache set a memory block maps to in a set-associative CPU cache. The address is conceptually divided into a tag, set-index field, and block or line offset.

The block offset selects a byte inside the cache line. The set index chooses the cache set. The remaining higher-order address portion acts as the tag used to distinguish different memory blocks that map to the same set.

Number of cache sets sets = cacheSize / (lineSize × associativity)
How to Use

How to Calculate a Cache Set Index

1
Enter the memory address Provide the byte address you want to map into the cache.
2
Enter cache size and line size Use sizes in bytes, such as a 32 KiB cache represented as 32768 bytes with 64-byte cache lines.
3
Enter associativity For an 8-way set-associative cache, enter 8. For a direct-mapped cache, enter 1.
4
Calculate address fields The tool derives cache sets and returns the set index, tag, line number, block offset, and bit counts.
Core Formula

Cache Set Index Formula

First convert the byte address into a cache-line number by dividing by the cache-line size.

Cache line number lineNumber = floor(address / lineSize)

Then reduce the cache-line number modulo the number of cache sets.

Set index setIndex = lineNumber mod numberOfSets
Worked Example

0x12345 in a 32 KiB, 64-Byte, 8-Way Cache

Example cache geometry
Address = 0x12345 Cache size = 32768 bytes Line size = 64 bytes Associativity = 8 ways Number of cache lines: 32768 / 64 = 512 lines Number of sets: 512 / 8 = 64 sets Cache-line number: 0x12345 / 64 = 1165 Block offset: 0x12345 mod 64 = 5 Set index: 1165 mod 64 = 13 Tag: 1165 / 64 = 18 decimal = 0x12
Block Offset

What Is the Cache Block Offset?

The block offset identifies the exact byte within the selected cache line. For a 64-byte line, valid offsets range from 0 through 63.

Block offset blockOffset = address mod lineSize

Because 64 equals 2⁶, a 64-byte line uses six low-order address bits for the block offset.

Index Bits

How Many Bits Are Used for the Set Index?

If the number of sets is an exact power of two, the number of index bits is the base-2 logarithm of the set count.

Set-index bits indexBits = log₂(numberOfSets)

A cache with 64 sets therefore requires 6 set-index bits because 64 = 2⁶.

Cache Tag

How the Cache Tag Is Calculated

After the block-offset and set-index portions are removed, the remaining higher-order address value is the cache tag.

Tag value tag = floor(lineNumber / numberOfSets)

In a power-of-two cache, this corresponds to shifting the address right by the total number of offset and index bits.

Bit Breakdown

Tag, Set Index, and Offset Address Fields

A conventional cache address decomposition can be visualized as three fields.

Address field structure
Higher bits Lower bits +—————-+—————+—————-+ | TAG | SET INDEX | BLOCK OFFSET | +—————-+—————+—————-+ For: 64-byte lines: offset bits = 6 64 sets: index bits = 6 So the lowest 12 address bits contain: 6 set-index bits 6 block-offset bits
Direct Mapped

Cache Set Index in a Direct-Mapped Cache

A direct-mapped cache has associativity 1. Each set contains exactly one cache line, so the number of sets equals the total number of lines.

Direct mapped sets = cacheSize / lineSize

The set-index calculation itself remains the same: lineNumber mod numberOfSets.

Associativity

How Associativity Changes the Number of Sets

Increasing associativity means more cache lines belong to each set, so the number of sets decreases for the same total cache size and line size.

Cache Size Line Size Ways Total Lines Sets
32 KiB 64 B 1 512 512
32 KiB 64 B 2 512 256
32 KiB 64 B 4 512 128
32 KiB 64 B 8 512 64
32 KiB 64 B 16 512 32
Cache Line Number

What Is a Cache-Line Number?

The cache-line number is the memory address divided by the line size using integer division. All byte addresses within the same aligned cache line have the same line number.

For a 64-byte line, addresses 0 through 63 belong to memory line 0, addresses 64 through 127 belong to line 1, and so on.

Memory block number lineNumber = address / lineSize
Power of Two

Why Cache Geometry Usually Uses Powers of Two

Power-of-two line sizes and set counts allow cache fields to correspond to fixed groups of address bits. This makes cache lookup efficient in digital hardware.

For example, a 64-byte line uses six low-order bits for the byte offset. If the cache has 128 sets, seven additional bits identify the set.

This calculator validates a power-of-two line size, associativity, and set count so the reported bit-field decomposition is mathematically consistent.
Example Reference

Cache Set Index Examples

Address Cache Line Ways Sets Set Index
0x12345 32 KiB 64 B 8 64 13
0x1000 32 KiB 64 B 8 64 0
0x1040 32 KiB 64 B 8 64 1
0x2000 32 KiB 64 B 8 64 0
0x12345 16 KiB 64 B 4 64 13
Same Set

Why Different Addresses Can Map to the Same Cache Set

The set index uses only part of the address. Different memory blocks whose line numbers differ by a multiple of the number of sets therefore map to the same set.

Their tag values differ, allowing the cache to distinguish them. In a set-associative cache, multiple such blocks can coexist in different ways of the same set until the set reaches its capacity.

Same set relationship
64 cache sets Line 13: 13 mod 64 = set 13 Line 77: 77 mod 64 = set 13 Line 141: 141 mod 64 = set 13 All three memory lines map to set 13, but their tags are different.
Cache Conflicts

Cache Set Index and Conflict Misses

When many actively used memory blocks map to the same cache set, they compete for the limited number of ways available in that set.

If more distinct blocks must remain active than the associativity permits, cache lines can evict one another and cause conflict misses.

A set-index calculator can therefore help when studying array strides, data-layout behavior, cache conflicts, or low-level performance patterns.

Applications

Where Cache Set Calculations Are Useful

Computer Architecture

Practice decomposition of addresses into tag, index, and block-offset fields.

Performance Analysis

Investigate whether address patterns repeatedly target the same cache sets.

Systems Programming

Reason about memory layout and cache-line placement in low-level software.

Data Structures

Study how arrays and records map into a set-associative cache.

Embedded Systems

Analyze cache geometry when working with known processor configurations.

Education

Verify manual cache-address calculations and bit-field exercises.

Important Limits

This Calculator Models Conventional Cache Indexing

The tool models a conventional physically indexed or directly address-based power-of-two set calculation using the cache geometry you provide.

Real processors can use more complex mechanisms, including virtual indexing, address hashing, slice selection, skewed organizations, undocumented mappings, or other microarchitecture-specific behavior.

Use the result when the cache is known to follow the standard line-number-modulo-set-count model. Processor-specific LLC slice selection or hashed indexing may require additional architecture-specific logic.
Common Mistakes

Common Cache Set Index Mistakes

Using the byte address directly modulo the number of sets

The block-offset portion must first be removed. Use the cache-line number, not the raw byte address, when calculating the set.

Ignoring associativity

Associativity changes how many sets the cache contains. A 32 KiB 8-way cache has fewer sets than a 32 KiB direct-mapped cache with the same line size.

Confusing total lines with number of sets

Total cache lines equal cache size divided by line size. Number of sets is total lines divided by associativity.

Using bits before validating powers of two

A clean fixed-bit index interpretation requires power-of-two line size and set count.

Assuming all real CPUs use simple indexing

Some processors use additional hashing or slice-selection functions, especially in higher-level shared caches.

FAQ

Cache Set Index Calculator FAQs

Divide the byte address by the cache-line size to get the line number, then take that line number modulo the number of cache sets.
Use cache size divided by line size and then divided by associativity.
It is the byte position inside the cache line, calculated as address modulo line size.
A 64-byte line equals 2^6 bytes, so it uses 6 block-offset bits.
It requires 6 index bits because 64 equals 2^6.
The tag is the higher-order address portion remaining after the block-offset and set-index fields are removed.
It means each cache set can contain eight cache lines, called ways.
Use associativity 1. Each set then contains exactly one cache line.
Yes. Different cache-line numbers can have the same remainder when divided by the set count, so they share a set but have different tags.
It can, because associativity changes the number of sets for a fixed cache capacity and line size.
It models conventional power-of-two cache indexing. Some processors use additional hashing, virtual indexing, or slice-selection functions.
Yes. It uses JavaScript BigInt for exact integer address and cache-field calculations.
Scroll to Top