Virtual address

On this page 7

A virtual address is a memory address used by a running program that refers to a location in its own private address space rather than to a specific cell of physical RAM. In operating systems, every load, store and instruction fetch uses virtual addresses, and the memory management unit translates each one into a physical address on the fly.

This indirection is the foundation of memory management: it lets each process believe it owns a large, contiguous memory region, while the kernel decides where the data actually lives, whether it is in RAM at all and who may access it.

How a virtual address is translated

With paging, the hardware splits a virtual address into a virtual page number and a page offset. The page number selects an entry in the page table, which supplies the physical page frame, and the offset is copied unchanged, because a page and a frame have the same size.

On x86-64 with 4 KiB pages, the lowest 12 bits form the offset and the remaining bits index a multi-level page table of four or five levels. Walking these levels for every access would be far too slow, so the CPU caches recent translations in the translation lookaside buffer, where a hit costs roughly one cycle and a miss triggers a page walk of tens to hundreds of cycles.

When the walk finds no valid mapping, the MMU raises a page fault. The kernel then either loads the page and retries the instruction, as in demand paging and copy-on-write, or delivers a segmentation fault when the address is truly invalid.

Bit rangeFieldPurpose
47 to 39Level 4 indexSelects entry in the top-level table
38 to 30Level 3 indexSelects entry in the next table
29 to 21Level 2 indexSelects entry or a 2 MiB huge page
20 to 12Level 1 indexSelects the final page table entry
11 to 0Page offsetByte position inside the 4 KiB page
Parts of a 48-bit x86-64 virtual address with 4 KiB pages

Virtual address versus physical address

The two kinds of address answer different questions: a virtual address says where data is from the program’s point of view, while a physical address says where it is on the memory bus. The comparison below summarizes the practical differences.

PropertyVirtual addressPhysical address
ScopePrivate to one address spaceGlobal to the whole machine
Generated byProgram instructionsMMU after translation
RangeSet by architecture, such as 48 or 57 bitsLimited by installed RAM and chipset
ContiguityContiguous ranges are commonFrames are usually scattered
UniquenessSame value can exist in many processesEach value names one location
Comparison of virtual and physical addresses

The same virtual address in two processes normally maps to two different frames. Conversely, two different virtual addresses can map to one shared frame, which is how shared libraries, shared memory and memory-mapped files avoid duplicate copies.

Address space size and canonical form

A 64-bit processor does not actually use all 64 bits of a virtual address. Current x86-64 and ARMv8 designs implement 48-bit addressing, giving 256 TiB, and newer chips offer 57-bit addressing with five-level paging, giving 128 PiB.

On x86-64, the unused upper bits must copy bit 47, a rule called canonical form. Non-canonical addresses fault immediately, which creates a large hole in the middle of the space; operating systems conventionally place user space in the lower half and the kernel in the upper half.

ArchitectureVirtual address bitsAddressable space
32-bit x86324 GiB
x86-64, four-level paging48256 TiB
x86-64, five-level paging57128 PiB
ARMv8-A, common configuration48256 TiB
Typical virtual address space sizes by architecture

On 32-bit systems, the 4 GiB limit was a real constraint, because the kernel reserved part of it, often 1 GiB or 2 GiB. On 64-bit systems, the virtual space is so large that physical RAM, not address bits, almost always limits how much memory a process can use.

What virtual addressing makes possible

Virtual addresses give the kernel three core capabilities that physical addressing alone cannot offer. Each relies on the fact that the program never sees where its memory really is.

  • Isolation and protection: a process cannot form an address that reaches another process’s memory, and page table bits enforce read, write and execute permissions.
  • Overcommitment and paging: pages can be absent from RAM, compressed or stored on disk, and are brought back transparently on access.
  • Flexible layout: features such as address space layout randomization, copy-on-write after fork and memory-mapped files depend on remapping virtual pages freely.

The price is translation overhead. Workloads with very large data sets can suffer from TLB misses, which is why databases and virtual machines often use huge pages of 2 MiB or 1 GiB to cover more memory per TLB entry.

Common misconceptions about virtual addresses

Several mistaken beliefs appear repeatedly in debugging sessions and performance discussions. The table pairs each with the accurate view.

MisconceptionAccurate view
Virtual memory means swap spaceTranslation exists even with no swap configured
A pointer value reveals the RAM locationPointers hold virtual addresses only
Large virtual size means high RAM useOnly resident pages consume physical memory
Addresses are stable across runsLayout randomization changes them each launch
Misconceptions and corrections

The third point matters most in practice: tools often report a large virtual size next to a much smaller resident set size, and only the latter reflects actual RAM consumption.

The simple explanation

Imagine a large hotel where guests never learn real room numbers. Each guest gets a personal list that says “my room 1, my room 2”, and only the front desk knows which real rooms those entries point to.

A virtual address works the same way. A program uses its own private numbering for memory, and the computer quietly translates each number into a real location in its memory chips. Because of this, programs cannot wander into each other’s rooms, and the system can move data around without the program ever noticing.

How it is used in practice

A developer debugging a crash in a C++ service on a Linux server sees the faulting pointer value 0x7f3a2c001000 in the log. Running the same build again produces a different value, because layout randomization places the heap at a new virtual address on every start.

Reading the process memory map shows that the faulting address lies just past the end of a mapped heap region, so no page table entry exists for it. The MMU raised a page fault, the kernel found no valid mapping and sent a segmentation fault. Fixing an off-by-one loop bound resolved the crash, and the physical location of the memory never needed to be known at any point.