Layering: OSI and TCP/IP
Why networks are built in layers, the vocabulary of service, interface and protocol, the seven OSI layers and the four or five TCP/IP layers with the unit of data (PDU) and the typical protocols and devices of each, encapsulation and de-encapsulation, and how header overhead adds up; the layer tables are quoted from the textbooks, the header arithmetic is computed.
Why it exists
Sending a web page from one computer to another involves electrical signals, bit errors, shared cables, routes across many networks, lost packets and the meaning of the page. No single piece of software handles all this. Layering splits the job into a stack of layers; each layer uses the services of the layer below, adds its own function and offers a service to the layer above. A layer can be replaced (Wi-Fi for Ethernet) without touching the others. GATE asks which layer does what, which device works at which layer and how headers add up.
Prerequisites
None.
Precise definitions
- A protocol is the set of rules (message formats and order) that two peer entities at the same layer on different machines follow.
- A service is what a layer offers to the layer above it; the interface is where the service is accessed (a layer sees the layer below only through its interface).
- A PDU (protocol data unit) is the unit of data a layer handles. A layer receives a PDU from above (its SDU), adds its own header (and sometimes a trailer), and passes the result down. This is encapsulation; the receiver reverses it (de-encapsulation) layer by layer.
The OSI reference model (seven layers, top to bottom) and TCP/IP (quoted, see verification notes):
| OSI layer | PDU | main job | TCP/IP layer | examples |
|---|---|---|---|---|
| 7 Application | message | services for the user program | Application | HTTP, DNS, SMTP, FTP |
| 6 Presentation | message | data representation, encryption, compression | (in Application) | TLS formatting, JPEG |
| 5 Session | message | dialogue control, synchronisation | (in Application) | session setup |
| 4 Transport | segment (TCP), datagram (UDP) | process-to-process delivery, reliability, flow and congestion control | Transport | TCP, UDP |
| 3 Network | packet (datagram) | host-to-host delivery, addressing, routing | Internet (Network) | IP, ICMP, routing protocols |
| 2 Data link | frame | node-to-node delivery on one link, framing, error detection, medium access | Link (Network access) | Ethernet, Wi-Fi |
| 1 Physical | bits | transmission of raw bits over a medium | Physical (in Link) | cables, signals |
TCP/IP is described with four layers (application, transport, internet, link) or five (the link layer split into data link and physical). Several books call the five-layer version the "hybrid model".
Devices by the highest layer they work at: hub and repeater: physical (layer 1); bridge and switch: data link (layer 2); router: network (layer 3); gateway (application-level proxy or protocol translator): up to layer 7.
Addresses by layer: port number (transport: identifies a process), IP address (network: identifies an interface of a host on an internetwork), MAC address (data link: identifies an interface on one link).
How it works
Encapsulation
An application hands bytes of data to TCP. TCP adds a header and passes a segment to IP; IP adds a header and passes a packet to the link; the link layer adds a header and a trailer and sends a frame. A router de-encapsulates up to layer 3, looks at the destination IP address, and re-encapsulates in a new frame for the next link; a switch looks only at the frame header.
Encapsulation: how headers add up: start
Computed by a script, not typed| added by | bytes | total so far | payload share of the total |
|---|---|---|---|
| application data | |||
| TCP header (no options) | |||
| IPv4 header (no options) | |||
| Ethernet header | |||
| Ethernet trailer (FCS) |
Step 0
The headers of the sizes shown are the minimum sizes (TCP 20, IPv4 20, Ethernet 14 + 4); the preamble of the physical layer is not counted.
The headers add bytes to bytes: the frame is bytes and percent of it is data. The share is lower for small payloads: a -byte request carried with the same headers has an efficiency of percent (the minimum Ethernet payload of bytes would additionally force padding, see the Ethernet page).
Who does what
- Reliability and ordering between processes: transport (TCP). Error detection on one link: data link (CRC, error detection). Routing: network (routing).
- Segmentation at transport, fragmentation at the network layer (IPv4 fragmentation), framing at the data link layer.
- The layers are end-to-end above the network layer (transport and application protocols run only in the hosts) and hop-by-hop below (each link has its own link protocol).
Worked examples
EX 1Which layer
Easy(a) Deciding which of several routes a packet takes: network layer. (b) Delivering data to the right process: transport (port numbers). (c) Detecting a corrupted frame on a link: data link. (d) Converting a character set or encrypting: presentation (OSI). (e) A switch: data link; a router: network.
EX 2Header arithmetic
EasyApplication data bytes, TCP , IP , Ethernet header , FCS : frame bytes. If the same data is sent in a frame that carries bytes of data per frame, two frames are needed and the total on the wire is bytes.
EX 3Number of layers a device inspects
MediumA message travels host, switch, router, switch, host. The sender builds all headers. Each switch reads only the data link header (the destination MAC address). The router removes the frame, reads the network header (the destination IP address) and builds a new frame for the next link. Only the two end hosts read the transport header. So the deepest layer reached is: application at the hosts, network layer at the router, data link at the switches.
EX 4Typical questions
GATE level(a) "Which layer provides process-to-process delivery?" Transport. (b) "The unit of data at the network layer?" Packet (datagram). (c) "In the OSI model, which layers are missing as separate layers in TCP/IP?" Session and presentation. (d) "A bridge operates at which layer?" Data link. (e) "Which layer is responsible for routing?" Network.
Cheat box
Cheat box
- OSI: Physical, Data link, Network, Transport, Session, Presentation, Application (bottom to top). TCP/IP merges the top three.
- PDUs: bits, frame, packet, segment, message.
- Encapsulation adds a header (data link also a trailer) at each layer going down.
- Hub: L1; switch and bridge: L2; router: L3.
- Address types: port (transport), IP (network), MAC (data link).
- Minimum headers: TCP 20, IPv4 20, Ethernet 14 + 4.
Traps and GATE patterns
Connections
Builds on
No prerequisites.
Across subjects
No cross-subject links yet.
Every later network page sits in one layer: error detection and medium access in the data link layer, IPv4 addressing and routing in the network layer, TCP in the transport layer, DNS and HTTP in the application layer. The idea of a layered interface is the same as the system-call interface between a program and the kernel (system calls).
PYQs
15 previous year questions from your book. I re-solved each one myself (3 by running or simulating, 12 by reasoning only); the book's key is shown next to my answer. All PYQs
Identify the ONE CORRECT matching between the OSI layers and their corresponding functionalities as shown.
- (a)
- (a)-(I), (b)-(II), (c)-(III)
- (b)
- (a)-(I), (b)-(III), (c)-(II)
- (c)
- (a)-(II), (b)-(III), (c)-(I)
- (d)
- (a)-(III), (b)-(II), (c)-(I)
In the following pairs of OSI protocol layer/sub- layer and its functionality, the INCORRECT pair is
- (a)Network layer and Routing
- (b)Data Link Layer and Bit synchronization
- (c)Transport layer and End-to-end process communication
- (d)Medium Access Control sub-layer and Channel sharing
Assume that source S and destination D are connected through two intermediate routers labeled R. Determine how many times each packet must visit the network layer and the data link layer during a transmission from S to D.
- (a)Network layer - 4 times and Data link layer - 4 times
- (b)Network layer - 4 times and Data link layer - 3 times
- (c)Network layer - 4 times and Data link layer - 6 times
- (d)Network layer - 2 times and Data link layer - 6 times
In Ethernet, when Manchester encoding is used, the bit rate is:
- (a)Half the baud rate
- (b)Twice the baud rate
- (c)Same as the baud rate
- (d)None of the above
A bit-stuffing based framing protocol uses an 8-bit delimiter pattern of 01111110. If the output bit- string after stuffing is 011111100101, then the input bit-string is:
- (a)0111110100
- (b)0111110101
- (c)0111111101
- (d)0111111111
Which of the following protocol pairs can be used to send and retrieve e-mails (in that order)?
- (a)IMAP, SMTP
- (b)IMAP, POP3
- (c)SMTP, MIME
- (d)SMTP, POP3
Which of the following is/are examples of stateful application layer protocols? (i) HTTP (ii) FTP (iii) TCP (iv) POP3
- (a)(i) and (ii) only
- (b)(ii) and (iii) only
- (c)(ii) and (iv) only
- (d)(iv) only
An IP machine Q has a path to another IP machine H via three IP routers R1, R2, and R3. Q - R1 - R2 - R3 - H H acts as an HTTP server, and Q connects to H via HTTP and downloads a file. Session layer encryption is used, with DES as the shared key encryption protocol. Consider the following four pieces of information: [I1] The URL of the file downloaded by Q [I2] The TCP port numbers at Q and H [I3] The IP addresses of Q and H [I4] The link layer addresses of Q and H Which of I1, I2, I3, and I4 can an intruder learn through sniffing at R2 alone?
- (a)Only I1 and I2
- (b)Only I1
- (c)Only I2 and I3
- (d)Only I3 and I4
The transport layer protocols used for real-time multimedia, file transfer, DNS, and email respectively are: COMPUTER NETWORK
- (a)TCP, UDP, TCP, and TCP
- (b)UDP, TCP, TCP, and UDP
- (c)UDP, TCP, UDP, and TCP
- (d)TCP, UDP, TCP, and UDP
The Protocol Data Unit (PDU) for the application layer in the Internet stack is
- (a)Segment
- (b)Datagram
- (c)Message
- (d)Frame
Which of the following transport layer protocols is used to support electronic mail?
- (a)SMTP
- (b)IP
- (c)TCP
- (d)UDP
A layer-4 firewall (a device that can look at all protocol headers up to the transport layer) CANNOT
- (a)block entire HTTP traffic during 9:00 pm and 5:00 am
- (b)block all ICMP traffic
- (c)stop incoming traffic from a specific IP address but allow outgoing traffic to the same IP address
- (d)block TCP traffic from a specific user on a multi-user system during 9:00 pm and 5:00 am
Consider the different activities related to email. ml : Send an email from mail client to mail server m 2 : Download an email from mailbox server to a mail client m3 ; Checking email in a web browser Which is the application level protocol used in each activity?
- (a)m1: HTTP m2: SMTP m3: POP
- (b)m1 : SMTP m2 : FTP m3 : HTTP
- (c)m1: SMTP m2: POP m3: HTTP
- (d)m1 : POP m2 : SMTP m 3 : IMAP
Which one of the following is not a client-server application?
- (a)Internet chat
- (b)Web browsing
- (c)E-mail
- (d)Ping
Match the following:
- (a)P-2, Q-1, R-3, S-5
- (b)P-1, Q-4, R-2, S-3
- (c)P-1, Q-4, R-2, S-5
- (d)P-2, Q-4, R-1, S-3
Self-check
Question 1
Name the PDU at the data link, network and transport layers.
Show answerHide
Frame, packet (datagram), segment (TCP) or datagram (UDP).
Question 2
Why can a layer be replaced without changing the others?
Show answerHide
Layers interact only through the service interface; the internal protocol of one layer is hidden from the others.
Question 3
A segment has bytes of header and carries bytes of data. It is sent in an IPv4 packet (20 byte header) and an Ethernet frame (14 + 4 bytes). How long is the frame?
Show answerHide
bytes.
Revision card
One-screen revision
- Layer = service to the layer above, protocol with the peer, interface with the layer below.
- Encapsulation adds headers going down; PDUs: bits, frame, packet, segment, message.
- OSI has 7 layers; TCP/IP 4 (or 5); hub L1, switch L2, router L3.
- Port, IP, MAC identify process, host interface, link interface.
References
- ·Kurose, Ross, Computer Networking: A Top-Down Approach (8th edition), Chapter 1, Section 1.5 (Protocol layers and their service models)
- ·Tanenbaum, Wetherall, Computer Networks (5th edition), Chapter 1, Sections 1.4 and 1.5 (Network software, reference models)
- ·Forouzan, Data Communications and Networking (5th edition), Chapter 2 (Network models)
Verification
The layer tables (names, order, PDU names, example protocols, devices) are QUOTED from the textbooks and need verification against the edition you use; books differ on the PDU name at some layers, on whether TCP/IP has four layers (Kurose uses five, Forouzan five, the original RFC 1122 four), and on the placement of some protocols (for example whether ARP is on the link or network layer). The only computed content is the header arithmetic in the encapsulation table (minimum header sizes TCP 20, IPv4 20, Ethernet 14 plus 4 bytes: also quoted from the standards, to be checked on the TCP, IPv4 and Ethernet pages), done in exact arithmetic by scripts/gen-cn1-traces.py. Textbook chapter references are from memory. SECOND PASS (2026-11-02, done by the assistant, not a human check): every Self-check question was solved before the printed answer was read and all agreed; the definitions, worked examples, cheat box and traps were read claim by claim and the numbers re-derived by hand or by a small script (CRC remainders, binomial tail, checksums); long C programs were not re-read line by line (they are compiled and compared by npm run verify:c, and their printed outputs were checked against the prose). No defect found. Status raised to self-checked; verified needs a textbook or human check.
last verified: never
My notes (saved in this browser)