Sub topic 2
The OSI and TCP/IP Models Layer by Layer
This chapter assumes you know why networks are layered (the previous chapter) and can read units such as bits, bytes and bits per second. It covers what each layer does, which protocols belong to it, and how the OSI and TCP/IP models line up. Encapsulation and device-by-layer details have their own chapters, so they appear here only where needed.
Two models, one purpose
A reference model divides the work of networking into layers. Each layer offers a service to the layer above it and uses the service of the layer below it.
- The OSI model (Open Systems Interconnection) was defined by ISO. It has seven layers and was designed as a general framework before most of its protocols existed.
- The TCP/IP model (also called the Internet model) grew out of protocols that were already in use. It has four layers in the original description. Many textbooks, including Kurose and Ross, use a five-layer version that splits the bottom layer in two.
GATE questions usually use OSI numbering (layers 1 to 7) but ask about TCP/IP protocols. You need both vocabularies.
The seven OSI layers
Layers are numbered from the bottom. Layer 1 is closest to the wire and layer 7 is closest to the user's program.
| No. | Layer | Main job | Unit of data | Typical examples |
|---|---|---|---|---|
| 7 | Application | Network services used by programs | Message | HTTP, SMTP, FTP, DNS |
| 6 | Presentation | Data format, encryption, compression | Message | Character encoding, TLS (often placed here) |
| 5 | Session | Dialog control, checkpoints, synchronization | Message | Session setup and recovery |
| 4 | Transport | Process-to-process delivery, reliability, flow control | Segment | TCP, UDP |
| 3 | Network | Host-to-host delivery across networks, routing, logical addressing | Packet | IP, ICMP, routing protocols |
| 2 | Data link | Node-to-node delivery on one link, framing, error detection, medium access | Frame | Ethernet, Wi-Fi, PPP |
| 1 | Physical | Moving raw bits as signals | Bit | Cables, voltage levels, modulation |
Physical layer
This layer sends individual bits over a medium. It defines voltages, light pulses or radio modulation, connector shapes, and bit rate. It knows nothing about frames or addresses.
Data link layer
This layer moves data between two nodes that share the same link. It groups bits into frames, adds error detection (such as a CRC), controls access to a shared medium, and uses MAC addresses to identify the next node. Its delivery is hop-to-hop, meaning that every link on a path runs its own data link protocol, and the frame is rebuilt at each hop.
Network layer
This layer delivers packets from the source host to the destination host, possibly across many links and networks. It supplies logical addresses (IP addresses) and routing. Its delivery is host-to-host. The network layer does not guarantee delivery in the Internet. IP is a best-effort service.
Transport layer
This layer delivers data between processes, not just machines. It uses port numbers to pick the right process on a host. TCP adds reliability, ordering, flow control and congestion control. UDP adds only ports and an optional checksum. Transport is end-to-end, which means only the two end hosts run it. Routers in the middle do not.
Session, presentation and application layers
- Session manages dialogs between applications. This includes opening, synchronizing with checkpoints, and closing them.
- Presentation handles syntax: translating between data formats, encrypting, and compressing.
- Application holds the protocols users' programs rely on, such as HTTP for the web and SMTP for mail.
In practice these three are not separate in the Internet. An application protocol is expected to handle session and presentation tasks itself.
The TCP/IP layers
The TCP/IP model collapses the OSI stack.
| TCP/IP layer (4-layer) | OSI layers covered | Examples |
|---|---|---|
| Application | 5, 6, 7 | HTTP, DNS, SMTP, FTP |
| Transport | 4 | TCP, UDP |
| Internet | 3 | IP, ICMP |
| Network access (link) | 1, 2 | Ethernet, Wi-Fi |
The five-layer variant splits network access into a link layer (OSI 2) and a physical layer (OSI 1).
The diagram shows how the OSI layers map onto the four-layer TCP/IP model.
Where OSI and TCP/IP differ
- Layer count. OSI has seven layers and TCP/IP has four (or five).
- Origin. OSI is a model first and its protocol suite was rarely deployed. TCP/IP protocols were deployed first, and the model describes them.
- Strictness. OSI separates service, interface and protocol clearly. TCP/IP is looser, and applications can access the transport and sometimes lower layers directly.
- Connection modes. OSI supports both connection-oriented and connectionless service at the network layer, but only connection-oriented service at the transport layer. TCP/IP offers only connectionless service at the Internet layer (IP), and offers both at the transport layer (TCP is connection-oriented and UDP is connectionless). This is a classic GATE fact.
Working out the layer of a protocol
A reliable way to place a protocol is to ask what it addresses and how far it delivers.
- If it identifies a process with a port, it is at the transport layer.
- If it identifies a host with an IP address across networks, it is at the network layer.
- If it identifies an interface with a MAC address on one link, it is at the data link layer.
- If it works with signals and bits only, it is at the physical layer.
The following program encodes a lookup for common protocols. It is a study aid and is not meant to be exhaustive.
OSI_LAYER_OF = {
"HTTP": 7, "SMTP": 7, "DNS": 7, "FTP": 7,
"TCP": 4, "UDP": 4,
"IP": 3, "ICMP": 3, "OSPF": 3,
"Ethernet": 2, "PPP": 2,
}
OSI_NAME = {
7: "Application", 6: "Presentation", 5: "Session", 4: "Transport",
3: "Network", 2: "Data link", 1: "Physical",
}
TCPIP_OF_OSI = {
7: "Application", 6: "Application", 5: "Application",
4: "Transport", 3: "Internet", 2: "Network access", 1: "Network access",
}
def describe(protocol):
layer = OSI_LAYER_OF[protocol]
return f"{protocol}: OSI layer {layer} ({OSI_NAME[layer]}), TCP/IP {TCPIP_OF_OSI[layer]}"
for name in ["HTTP", "UDP", "ICMP", "Ethernet"]:
print(describe(name))The output is:
HTTP: OSI layer 7 (Application), TCP/IP Application
UDP: OSI layer 4 (Transport), TCP/IP Transport
ICMP: OSI layer 3 (Network), TCP/IP Internet
Ethernet: OSI layer 2 (Data link), TCP/IP Network accessCommon errors and edge cases
ARP and ICMP do not sit cleanly in one layer
ICMP messages are carried inside IP packets, yet ICMP is considered a network-layer protocol because it supports IP itself. ARP maps an IP address to a MAC address. Textbooks usually place it between layers 2 and 3. If an exam forces a single choice, the usual answer is the network layer (OSI 3), but check the options given.
Routing protocols and their carriers
RIP runs over UDP, OSPF runs directly over IP, and BGP runs over TCP. All three are still described as network-layer functions, even though the carrier is a transport protocol in the RIP and BGP cases. When a question asks about the layer of the function, answer network layer. When it asks about the protocol carrying the message, answer according to the carrier.
Mixing up delivery scopes
Keep these three separate:
- Data link: node to node, one hop.
- Network: host to host, source to destination.
- Transport: process to process, end to end.
A frequent mistake is to say "the data link layer provides end-to-end reliability". It does not. Data link error detection covers only one link. A packet corrupted inside a router's memory would pass link-layer checks on both sides of that router, and only an end-to-end check at the transport layer or above catches it.
Reliability is not owned by one layer
Error control can appear at the data link layer, as in some wireless links, and at the transport layer, as in TCP. The end-to-end argument says the end hosts must verify correctness anyway, so link-level recovery is mainly a performance optimization.
Address types per layer
Each layer uses a different identifier, and a full delivery needs all of them.
| Layer | Identifier | Scope |
|---|---|---|
| Application | Domain name, URL | Global |
| Transport | Port number | One host |
| Network | IP address | Across networks |
| Data link | MAC address | One link |
Only the MAC address changes at every hop. The IP addresses stay the same from source to destination (ignoring address translation), and the port numbers stay the same end to end.
Models versus real stacks
A model is a description, not a rulebook. Real protocols sometimes cross layers. For example, TLS sits between transport and application, and tunnels carry one protocol inside another. Use the models to reason about responsibilities, and do not expect every protocol to have a single exact layer.
Exercises
Exercise
A frame carries an IP packet that carries a TCP segment. Which identifier changes at every router along the path, and which identifier stays the same from source to destination? Name the layer of each.
Show answer
The MAC address (data link layer) changes at every hop because each link has its own frame addressing. The IP address (network layer) stays the same from source to destination, and the TCP port number (transport layer) also stays the same.
Exercise
State which statement is true for the OSI model and which for TCP/IP: "the network layer offers only connectionless service" and "the transport layer offers both connectionless and connection-oriented service".
Show answer
Both statements are true for TCP/IP: IP is the only network-layer protocol and is connectionless, and the transport layer has UDP (connectionless) and TCP (connection-oriented). In OSI the network layer supports both modes and the transport layer supports only connection-oriented service, so neither statement holds for OSI.
Exercise
Which TCP/IP layer corresponds to the OSI session, presentation and application layers together, and what happens to the work those three do in practice?
Show answer
The TCP/IP application layer. Application protocols such as HTTP handle session management and data formatting themselves, so there are no separate session and presentation layers in the Internet stack.