GATE/Computer Networks/OSI Model & TCP/IP Stack
Easy12 min readComputer Networks

OSI Model & TCP/IP Stack

The OSI model provides a 7-layer reference framework; TCP/IP is the practical 4-layer implementation. GATE tests layer responsibilities, protocols at each layer, and encapsulation.

Key Points

  • ·OSI: Physical → Data Link → Network → Transport → Session → Presentation → Application
  • ·TCP/IP: Network Access → Internet → Transport → Application (4 layers)
  • ·Encapsulation: data → segment → packet → frame → bits as it descends layers
  • ·Physical: bits, signals, cables, hubs, repeaters
  • ·Data Link: framing, MAC addresses, error detection, switches, bridges
  • ·Network: IP addressing, routing, packet forwarding, routers
  • ·Transport: end-to-end delivery, TCP (reliable) and UDP (unreliable)
  • ·Application: HTTP, FTP, SMTP, DNS, DHCP — user-facing protocols
  • ·PDU names: bits (Physical), frames (Data Link), packets (Network), segments (Transport)

What is a Computer Network?

Analogy: Sending a letter through the postal system. You write the letter (Application), put it in an envelope with an address (Transport/Network), hand it to a truck (Data Link/Physical). Each step adds its own label. At the destination, labels are peeled off in reverse.

This "layering" is exactly what the OSI and TCP/IP models describe.


The OSI 7-Layer Model

Memory trick (bottom to top): "Please Do Not Throw Sausage Pizza Away" Physical, Data Link, Network, Transport, Session, Presentation, Application

Layer 7 - Application:  User-facing protocols: HTTP, FTP, SMTP, DNS, DHCP
Layer 6 - Presentation: Format/encrypt/compress: SSL/TLS, JPEG, ASCII
Layer 5 - Session:      Manage sessions: NetBIOS, RPC
Layer 4 - Transport:    End-to-end delivery: TCP, UDP
Layer 3 - Network:      Logical addressing + routing: IP, ICMP, OSPF
Layer 2 - Data Link:    Framing + MAC addresses: Ethernet, Wi-Fi (802.11)
Layer 1 - Physical:     Raw bits on wire: cables, hubs, signals
Layer PDU Name Device
Application Data
Transport Segment
Network Packet Router
Data Link Frame Switch, Bridge
Physical Bits Hub, Repeater

TCP/IP Model — The Real Internet

OSI Layers               TCP/IP Layers
Application  ──────────┐
Presentation ───────── ├── Application (HTTP, FTP, DNS, SMTP, DHCP)
Session      ──────────┘
Transport    ──────────── Transport (TCP, UDP)
Network      ──────────── Internet (IP, ICMP, ARP)
Data Link    ──────────┐
Physical     ──────────┘── Network Access (Ethernet, Wi-Fi, Fiber)

Encapsulation — Wrapping at Each Layer

Analogy: Your message goes into an envelope (Transport), that envelope goes into a box (Network), that box goes into a delivery truck container (Data Link), which travels as a physical shipment (Physical).

Sender (top-down):
Application creates DATA
Transport adds TCP header → [TCP HDR | DATA]  = SEGMENT
Network adds IP header   → [IP HDR | SEGMENT]  = PACKET
Data Link adds frame header/trailer → [ETH HDR | PACKET | ETH TRL] = FRAME
Physical transmits as bits on wire

Receiver (bottom-up): strip headers in reverse order

Devices and Their Layers

Device Layer How it works
Hub Layer 1 Broadcasts every bit to ALL ports — dumb!
Bridge Layer 2 Reads MAC, forwards to correct port (or floods)
Switch Layer 2 Smart bridge — learns MAC table, selective forwarding
Router Layer 3 Reads IP, looks up routing table, forwards to next hop
Gateway All Translates between different protocols/architectures

IP Addressing (IPv4)

IPv4 address = 32 bits = 4 octets: 192.168.1.100
CIDR notation: 192.168.1.0/24 means:
  first 24 bits = network part (192.168.1)
  last 8 bits   = host part (.0 to .255)

Network address:   host part all 0s  → 192.168.1.0
Broadcast address: host part all 1s  → 192.168.1.255
Usable hosts:      2^(32-24) - 2 = 254 hosts

Private IP ranges (not routed on the internet):

10.0.0.0/8         (16 million addresses)
172.16.0.0/12      (1 million addresses)
192.168.0.0/16     (65,000 addresses)

Subnetting — Dividing a Network

Example: You have 192.168.1.0/24 and need 4 subnets.

Need 4 subnets → borrow 2 bits (2² = 4) → new prefix = /26
Each subnet has 2^(32-26) - 2 = 62 usable hosts

Subnet 1: 192.168.1.0/26   (hosts .1 to .62,  broadcast .63)
Subnet 2: 192.168.1.64/26  (hosts .65 to .126, broadcast .127)
Subnet 3: 192.168.1.128/26 (hosts .129 to .190, broadcast .191)
Subnet 4: 192.168.1.192/26 (hosts .193 to .254, broadcast .255)

GATE Quick Formula: Usable hosts = 2^h - 2 where h = host bits = 32 - prefix length


Common Protocols at Each Layer

Protocol Layer Purpose
HTTP/HTTPS Application Web pages
FTP Application File transfer
SMTP Application Email sending
DNS Application Name → IP resolution
DHCP Application Auto-assign IP addresses
TCP Transport Reliable, ordered delivery
UDP Transport Fast, unreliable delivery
IP Network Logical addressing, routing
ICMP Network Error messages (ping, traceroute)
ARP Data Link/Network IP → MAC address mapping

Quick Check

Q1. Which layer adds the IP address header? Answer: Layer 3 — Network layer. IP header contains source and destination IP addresses.

Q2. Network 10.0.0.0/22. How many usable hosts?

Host bits = 32 - 22 = 10 bits
Usable hosts = 2^10 - 2 = 1024 - 2 = 1022 hosts

Q3. A switch vs a router — what is the key difference? Answer: Switch operates at Layer 2 using MAC addresses for forwarding within the same network. Router operates at Layer 3 using IP addresses to forward between different networks.

Key Formulas

  • Usable hosts = 2^h - 2 where h = 32 - prefix length
  • Network address = IP AND subnet mask
  • Broadcast address = IP OR (NOT subnet mask)

GATE Exam Tips

  • PDU at each layer: bits → frames → packets → segments → data (bottom to top).
  • Switches operate at Layer 2 (Data Link); routers at Layer 3 (Network).
  • GATE frequently tests subnetting — practice CIDR calculations quickly.
  • Transport layer provides end-to-end delivery; network layer provides hop-by-hop routing.

Finished reading this topic?

Mark it complete to track your study progress.