Understanding the virtual address page number and offset calculator — concept and principle
With paged virtual memory, the processor splits every virtual address into a page number, which the page table translates to a physical frame, and an offset, which is copied unchanged into the physical address. This calculator performs that split for a hexadecimal address and a page size in KiB. It is used in operating-systems courses, when reading crash dumps and debugger output, and when reasoning about TLBs and huge pages.
How it is calculated
- Page number = ⌊address ÷ page size⌋
- Offset = address mod page size
- Offset bits = log₂(page size in bytes)
Page size is entered in KiB and multiplied by 1,024. The address is read as hexadecimal (with or without "0x") and handled as an arbitrary-precision integer, so 64-bit addresses work. Results are shown in hexadecimal.
The principle
Page sizes are powers of two, so dividing by the page size is the same as shifting right by k bits, and the remainder is just the lowest k bits. With 4 KiB pages, k = 12: the low 12 bits (three hex digits) form the offset and the remaining high bits form the page number. Every byte within a page shares the same page number, so a single page-table entry can map a whole page.
Worked example
- Address 0x7FFE1234, page size 4 KiB = 4,096 bytes = 2^12.
- Offset bits: log₂(4,096) = 12.
- Page number: 0x7FFE1234 ÷ 4,096 = 2,147,357,236 ÷ 4,096 = 524,257 remainder 564; 524,257 = 0x7FFE1.
- Offset: 564 = 0x234.
- Check: drop the last three hex digits for the page and keep them for the offset.
How to read the result
The offset tells you where in the page the byte lies and stays the same after translation. The page number is the index the MMU looks up. With 2 MiB huge pages the offset grows to 21 bits, so far fewer entries cover the same memory.
Common mistakes
- Entering the page size in bytes instead of KiB.
- Using a page size that is not a power of two.
- Assuming the page number is a physical address; it still needs the page table to become a frame number.
Frequently asked questions
How many pages fit in a 32-bit address space with 4 KiB pages?
2^32 ÷ 2^12 = 2^20, about one million pages.
How is the physical address formed?
Physical address = frame number × page size + offset; the offset is unchanged.
Why does x86-64 use 4 KiB pages?
It is the base page size of the architecture; 2 MiB and 1 GiB pages are also supported for large mappings.
Sources: A. Silberschatz, P. B. Galvin, G. Gagne, Operating System Concepts, Wiley (chapter on main memory and paging) · Intel 64 and IA-32 Architectures Software Developer's Manual, Volume 3A (paging)