# Segmentation vs paging and segmented paging

> What is segmentation? How does it differ from paging, and what is segmented paging?

Canonical: https://www.internhack.in/learn/interview/operating-systems-interview/os-segmentation-vs-paging
Last updated: 2026-11-28

Difficulty: Intermediate

## Question

What is segmentation? How does it differ from paging, and what is segmented paging?

## Answer

Paging and segmentation both map logical addresses to physical ones, but they start from two very different philosophies. Paging divides memory into equal, arbitrary chunks that the programmer never sees. Segmentation divides memory into variable-size pieces that correspond to how programmers think about their program. A useful analogy is a book. Paging is like cutting a book into identical 10-page bundles regardless of chapter boundaries, so a chapter may get split across bundles. Segmentation is keeping each chapter as its own unit, chapters having different lengths.

In segmentation, a program is a collection of logical units called segments: the main program, functions, the stack, the heap, the symbol table, global data. A logical address is a pair (segment number, offset). The OS keeps a segment table for each process, where each entry holds a base (starting physical address of the segment) and a limit (length). Translation: use the segment number to find the entry, check that offset is less than limit (otherwise raise a segmentation fault trap), and compute physical address as base plus offset. Because segments correspond to program structure, it is natural to attach protection and sharing to them: mark the code segment read-only and executable, mark the stack non-executable, and share a library's code segment between processes.

Now the differences. Segment size is variable, whereas page size is fixed by hardware. Segmentation is visible to the programmer or compiler, paging is invisible and handled by the OS and hardware. Segmentation suffers from external fragmentation because variable-size chunks leave awkward holes in memory that may need compaction, whereas paging suffers from internal fragmentation in the last page. Paging address translation splits a single linear address by bit positions, while segmentation needs an explicit two-part address. Paging is better for efficient memory utilization and simple allocation, while segmentation is better for logical organization, protection and sharing.

Wait, does the address in a modern program have a segment? On x86-32, yes, hardware segment registers (CS, DS, SS) exist, but modern 64-bit operating systems use a flat memory model where segment bases are effectively zero and paging does all the real work. The term segmentation fault survives historically: it signals an invalid memory access, even though the mechanism is now a page fault that the OS cannot resolve.

The hybrid approach is segmented paging, used by the original Intel 80386 and Multics. The address space is first divided into segments, and each segment is then paged. A logical address is (segment, page, offset). The segment table entry points to a page table for that segment instead of a base address. This keeps the logical benefits of segmentation such as protection and sharing, while eliminating external fragmentation by allocating pages in fixed-size frames. The price is more table lookups per translation, which the TLB mitigates, and more table overhead.

If asked for a quick numerical example: with a segment table entry base = 1400 and limit = 1000 for segment 2, the logical address (2, 400) maps to 1400 + 400 = 1800, but (2, 1100) exceeds the limit and traps.

## Key points

- Segments are variable-size logical units; pages are fixed-size physical units.
- Segment table stores base and limit; offset must be less than limit.
- Segmentation causes external fragmentation; paging causes internal fragmentation.
- Modern 64-bit systems use a flat model and rely on paging.
- Segmented paging combines logical protection with fixed-size allocation.

## Common follow-up questions

- Why is a segmentation fault called that today?
- Which fragmentation does each scheme suffer from?
- What is compaction?
- How does segmented paging translate an address?

## Interview tips

- State the philosophy difference (programmer view versus system view) before the table.
- Give a numeric base and limit example to show translation.
- Mention that modern x86-64 mostly uses flat paging.

## Concepts covered

segmentation, paging, segment table, logical address, protection

Previous: [Paging, page tables and the TLB](https://www.internhack.in/learn/interview/operating-systems-interview/os-paging-page-tables-and-tlb) · Next: [Internal vs external fragmentation and how to reduce them](https://www.internhack.in/learn/interview/operating-systems-interview/os-internal-vs-external-fragmentation) · [All of Operating Systems](https://www.internhack.in/learn/interview/operating-systems-interview)

## More Operating Systems questions

- [Virtual memory, demand paging and page faults](https://www.internhack.in/learn/interview/operating-systems-interview/os-virtual-memory-and-demand-paging)
- [Page replacement: FIFO, LRU and Optimal with a worked example](https://www.internhack.in/learn/interview/operating-systems-interview/os-page-replacement-fifo-lru-optimal)
- [Thrashing and Belady's anomaly](https://www.internhack.in/learn/interview/operating-systems-interview/os-thrashing-and-beladys-anomaly)
- [File systems, inodes and directory structure](https://www.internhack.in/learn/interview/operating-systems-interview/os-file-systems-and-inodes)
- [Disk scheduling: FCFS, SSTF, SCAN and C-SCAN](https://www.internhack.in/learn/interview/operating-systems-interview/os-disk-scheduling-algorithms)
- [What is an Operating System and what are its main functions?](https://www.internhack.in/learn/interview/operating-systems-interview/os-what-is-an-operating-system)

## Related

- [Learn](https://www.internhack.in/learn)
- [Interview Prep](https://www.internhack.in/learn/interview)
- [Operating Systems](https://www.internhack.in/learn/interview/operating-systems-interview)
