Layering is needed because network communication is a very complex task; dividing it into layers, each doing a well-defined job and offering services to the layer above, makes networks easier to design, build, standardise and maintain.
Reasons / advantages of layering
- Divide and conquer: the large problem (moving data between applications on different machines) is split into smaller sub-problems: physical transmission, framing, routing, end-to-end delivery, presentation, application services.
- Modularity and independence: each layer can be changed or upgraded without affecting others as long as the interface stays the same (e.g. replacing Ethernet with Wi-Fi does not change TCP or HTTP).
- Abstraction: a layer only needs to know the services of the layer below, not how they are implemented.
- Standardisation and interoperability: clear layer boundaries allow different vendors to build compatible hardware and software (OSI, TCP/IP).
- Easier troubleshooting: problems can be isolated layer by layer (cable fault vs IP address error vs application error).
- Reusability: one lower-layer service is shared by many upper-layer protocols (IP carries TCP, UDP, ICMP).
- Easier teaching and development: engineers can specialise in one layer.
How it works: layer \(n\) on one machine talks logically to layer \(n\) on the other (peer-to-peer communication using a protocol), while physically the data passes down through the layers, each adding its header (encapsulation), across the medium, and up the other stack where headers are removed.
Drawbacks: some overhead from extra headers and processing, and duplication of functions (e.g. error control in more than one layer).