Segmentation in an operating system is a memory management technique that divides a program into variable-sized logical parts called segments, such as code, data, stack, or modules. It helps the OS manage memory more naturally, based on how the program is structured, rather than using fixed- size chunks.

Quick Scoop

In segmentation, each segment can be placed in different, non-contiguous areas of memory , and the OS uses a segment table to map a segment number plus offset to the actual physical address.

This makes it useful for protection, sharing, and modular organization , but it can also lead to external fragmentation.

How it works

A logical address usually has two parts:

  1. Segment number
  2. Offset within that segment.

For example, if a program has separate code and stack segments, the OS stores them independently and uses the segment table to find the right location in RAM.

Why it is used

  • It matches the user’s view of a program better than paging.
  • It supports memory protection so one segment cannot easily interfere with another.
  • It allows sharing of segments between processes when needed.

Difference from paging

Feature| Segmentation| Paging
---|---|---
Unit size| Variable-sized segments 37| Fixed-size pages 17
Basis| Logical parts of a program 79| Memory management convenience 17
Fragmentation| External fragmentation can happen 3| Internal fragmentation can happen 1

Simple example

Think of a program like a book:

  • Chapters = segments.
  • Each chapter has its own place and purpose.
  • The OS keeps track of where each chapter is stored and how to reach a specific page inside it.

If you want, I can also explain segmentation with a diagram or give you a 2-mark exam answer.