Paging vs. Segmentation: How Operating Systems Manage Memory

Every running process needs memory, and the operating system has to decide how to hand it out. Two classical strategies exist: segmentation, which divides memory along the logical structure of a program, and paging, which divides it into fixed-size blocks. Modern Linux, Windows, and macOS all use paging in practice. This article explains both approaches, why paging won, and where you actually notice the difference as a developer.

Segmentation: Memory That Mirrors Your Program

In a segmented memory model, a process's address space is split into variable-sized segments that correspond to program structure: a code segment, a data segment, a stack segment, and so on. Each segment is described by a base address (where it starts in physical memory) and a limit (its size), and a segment selector identifies the segment being accessed.

The x86 architecture was designed around this idea — registers like CS, DS, and SS point to code, data, and stack segments, and the CPU checks every access against the segment's limit. That check is the original hardware-level memory protection mechanism: one process could not reach outside its segments because the CPU would raise a fault.

The fundamental weakness is external fragmentation. Because segments are variable-sized, allocating and freeing them over time leaves small holes between segments that are individually too small to be used, even when the total free memory is large. Fixing it requires compaction — moving segments around in physical memory — and every pointer into a moved segment breaks unless the OS updates it.

Paging: Fixed-Size Blocks and a Page Table

Paging ignores program structure entirely. Virtual memory is cut into fixed-size blocks called pages — 4 KB on most Linux and x86-64 systems, with 2 MB "huge pages" available on servers — and physical memory into equally sized frames. A per-process page table maps every virtual page to a physical frame.

This eliminates external fragmentation by construction: any page fits into any free frame, so memory never gets riddled with unusable gaps. The costs are:

What x86 Actually Does Today

On modern 64-bit systems, addresses are translated through multiple levels of page tables, and segments still exist in the architecture but are configured "flat" — base 0, no limit — so they effectively do nothing. Linux uses the FS segment register for thread-local storage, which is about the only place segments matter in practice. The segment-based scheme above lives on mainly in textbooks, 80386 era tutorials, and languages like early C runtimes that referenced segment registers directly.

Why Paging Won

Where You Notice This as a Developer

Comparison Table

Feature Paging Segmentation
Memory division Fixed-size pages (e.g., 4 KB) Variable-size segments
Fragmentation Internal (wasted space inside a page) External (unusable gaps between segments)
Addressing Page number + offset, via page table Segment number + offset, via segment table
Protection granularity Per page Per segment (code/data/stack)
Supports demand paging / swapping Yes Not practically
Used by modern OS kernels Yes (Linux, Windows, macOS) No (flat model + paging)

Summary

Paging wins because it trades a little wasted space per page for a memory model that has no external fragmentation, supports demand paging, copy-on-write, and cheap sharing — properties a modern multitasking kernel needs. Segmentation's only real advantages, logical organization and fine-grained protection, are now handled by paging plus per-region access flags. When you are debugging a process's memory usage on Linux, you are almost always debugging paging.

A.M. Rinas

Written by A.M. Rinas

Full-Stack Software Engineer working on web applications, DevOps automation, and databases. More about me on the about page, or say hi through the contact page and LinkedIn.

← Back to all articles