What is the difference between paging and segmentation?
Paging divides memory into fixed-size pages invisible to the programmer; segmentation divides it into variable-size logical units like code, stack and heap. Paging causes internal fragmentation, segmentation causes external.
Explain it simply
Paging is cutting a long cloth into equal 1-metre pieces regardless of the pattern. Segmentation is cutting along the pattern: one piece for the sleeve, one for the collar, each a different size.
| Point | Paging | Segmentation |
|---|---|---|
| Unit size | Fixed (page) | Variable (segment) |
| Visible to programmer | No | Yes, matches program structure |
| Address | page number + offset | segment number + offset |
| Table | Page table | Segment table (base, limit) |
| Fragmentation | Internal | External |
| Sharing and protection | Per page | Natural per segment (e.g. share code) |
Example
A program has a code segment, a data segment and a stack segment. With segmentation, address (2, 100) means "byte 100 of the stack segment". Each segment has its own base and limit, so the stack can grow and be protected separately from the code.
With paging, the same program is split blindly into equal pages. The hardware does not know which page is code and which is stack, though per-page permission bits still give protection.
Many real systems combine them. Older x86 systems used segmentation with paging; modern 64-bit x86 mostly uses paging, with segmentation reduced to a minimal role.
What to say in the interview
"Paging uses fixed-size pages, avoids external fragmentation and is invisible to the programmer. Segmentation uses variable-size logical segments, suffers external fragmentation, and matches how programmers think. Many systems combine both."
Common mistakes
- Saying segmentation has no protection. Each segment has a limit and permissions.