Network Layer — IP, Subnetting & Routing
The Network layer handles logical addressing and packet routing. GATE tests IPv4 addressing, CIDR subnetting, routing algorithms (Dijkstra, Bellman-Ford), and distance vector vs link state protocols.
Key Points
- ·IPv4: 32-bit address; subnet mask separates network and host parts
- ·CIDR notation: 192.168.1.0/24 means 24 bits for network, 8 for host → 254 usable hosts
- ·Subnetting: divide one network into smaller subnetworks by borrowing host bits
- ·ARP: maps IP address to MAC address within a subnet
- ·ICMP: error reporting and diagnostics (ping uses ICMP Echo, traceroute uses TTL)
- ·Distance Vector (RIP): each router shares routing table with neighbours; Bellman-Ford based
- ·Link State (OSPF): each router floods complete topology; Dijkstra based; faster convergence
- ·BGP: Border Gateway Protocol — inter-AS routing; path vector
- ·NAT: maps private IPs to public IPs; IPv6 has 128-bit addresses
IP — The Internet Protocol
Analogy: IP addresses are like postal addresses. Your home address uniquely identifies where you live. When sending a letter across the country, each post office (router) reads the address and forwards the letter to the next post office, until it arrives.
IPv4 Address Structure
32-bit address divided into 4 octets: 192.168.10.1
CIDR notation: IP/prefix_length
IP: 11000000.10101000.00001010.00000001 (binary of 192.168.10.1)
Mask/24: 11111111.11111111.11111111.00000000
Network part: first 24 bits = 192.168.10
Host part: last 8 bits = .1
Network address = IP AND mask = 192.168.10.0
Broadcast = IP OR (NOT mask) = 192.168.10.255
Usable hosts = 2^8 - 2 = 254
Subnetting — The GATE Favourite
Step-by-step method:
Given: 172.16.0.0/16, divide into subnets with at least 500 hosts each.
Step 1: How many host bits needed?
2^h - 2 ≥ 500 → 2^9 = 512 ≥ 500 + 2 ✓ (h = 9)
Step 2: New prefix = 32 - 9 = /23
Original was /16, now /23 → borrowed 7 bits for subnets
Step 3: Number of subnets = 2^7 = 128 subnets
Step 4: Each subnet range = 2^9 = 512 addresses wide
Subnet 0: 172.16.0.0/23 (172.16.0.0 to 172.16.1.255)
Subnet 1: 172.16.2.0/23 (172.16.2.0 to 172.16.3.255)
...
ARP — Address Resolution Protocol
Problem: I know IP address 192.168.1.5, but I need MAC address to send Ethernet frame.
Solution:
1. Broadcast ARP request: "Who has IP 192.168.1.5? Tell 192.168.1.10"
(Sent to FF:FF:FF:FF:FF:FF = broadcast MAC)
2. Only 192.168.1.5 replies: "I am 192.168.1.5 at MAC AA:BB:CC:DD:EE:FF"
3. Requester caches in ARP table (to avoid repeat broadcasts)
Key: ARP works only within ONE subnet.
Sending to another subnet → ARP for the DEFAULT GATEWAY MAC, not destination.
Routing Algorithms
Distance Vector (Bellman-Ford) — RIP
Analogy: Ask your neighbours where to go. Each router knows only what its directly connected neighbours say. Builds routing table by sharing tables with neighbours periodically.
Bellman-Ford equation: d(x, y) = min over all neighbours v { cost(x,v) + d(v,y) }
Algorithm:
1. Each router starts: cost to self = 0, cost to all others = ∞
2. Share routing table with all direct neighbours periodically
3. Update: if I can reach Y via V at lower cost → update table
4. Converge after several rounds
Problem: COUNT-TO-INFINITY
If a link fails, good news spreads fast, bad news spreads slowly.
Routers may cycle through, each increasing cost by 1, until max hop count.
Fix: split horizon (never advertise route back through same interface),
poison reverse (advertise failed route as ∞ back to sender)
Protocol: RIP — max 15 hops (16 = infinity = unreachable)
Link State (Dijkstra) — OSPF
Analogy: Every router gets a complete MAP of the network. Each floods its "hello" (which links it has and their costs) to all routers. Once everyone has the full map, each runs Dijkstra to find shortest paths.
Steps:
1. Each router discovers neighbours and link costs
2. Floods Link State Advertisement (LSA) to ALL routers
3. Each router builds complete topology database
4. Each router independently runs Dijkstra's algorithm for SSSP
5. Install shortest paths in routing table
Advantages:
✓ Faster convergence (floods immediately on change)
✓ No count-to-infinity
✓ Better for large networks
Protocol: OSPF (Open Shortest Path First) — uses cost metric (related to bandwidth)
Comparison
┌──────────────────┬───────────────────┬──────────────────┐
│ │ Distance Vector │ Link State │
├──────────────────┼───────────────────┼──────────────────┤
│ Algorithm │ Bellman-Ford │ Dijkstra │
│ Information sent │ Routing table │ Link costs only │
│ Sent to │ Direct neighbours │ ALL routers │
│ Convergence │ Slow │ Fast │
│ Count-to-∞ │ Yes │ No │
│ Complexity │ O(VE) per router │ O(V²) per router │
│ Protocol │ RIP │ OSPF │
└──────────────────┴───────────────────┴──────────────────┘
ICMP — Network Diagnostics
ICMP = Internet Control Message Protocol (runs over IP)
ping: sends ICMP Echo Request, expects Echo Reply
Tests if host is reachable and measures RTT
traceroute: sends packets with increasing TTL (Time To Live)
TTL=1: first router drops it and sends ICMP "Time Exceeded" back → reveals router 1
TTL=2: second router → reveals router 2
... until destination reached
IPv6 — The Future
128-bit addresses (vs 32-bit IPv4)
Written as 8 groups of 4 hex digits: 2001:0db8:85a3::8a2e:0370:7334
Total addresses: 2^128 ≈ 3.4 × 10^38 (enough for every grain of sand!)
Key improvements over IPv4:
✓ No NAT needed (enough addresses for every device)
✓ Built-in IPSec (security)
✓ Simplified header (faster routing)
✓ Stateless Address Autoconfiguration (SLAAC)
Quick Check
Q1. IP = 192.168.5.130/26. What is the network address and broadcast?
/26 mask = 255.255.255.192 = 11000000 in last octet
130 in binary = 10000010
Network bits: 10 (= 128), Host bits: 000010
Network address = 192.168.5.128
Broadcast = 192.168.5.191 (host bits all 1s = 128+63)
Q2. What is the count-to-infinity problem in distance vector routing? Answer: When a link fails, bad news propagates slowly. Router A says cost to X is ∞, but B still thinks it can reach X via A (cost 2). A updates to say cost via B = 3, B updates via A = 4, etc. This cycles until infinity, converging very slowly.
Q3. Why does OSPF converge faster than RIP? Answer: OSPF floods link-state changes immediately to all routers. RIP only shares tables with neighbours periodically (every 30 seconds), so topology changes take many rounds to propagate.
Key Formulas
- Usable hosts: 2^h - 2 where h = 32 - prefix length
- Bellman-Ford: d(x,y) = min_v {cost(x,v) + d(v,y)}
GATE Exam Tips
- ★Subnetting: key formula is 2^h - 2 hosts, and subnets increase by powers of 2.
- ★RIP max hop count = 15 (16 = infinity = unreachable).
- ★Distance vector has count-to-infinity; link state does NOT (everyone has the full map).
- ★ARP resolves IP → MAC within a subnet. For outside subnet, ARP for the gateway MAC.
Finished reading this topic?
Mark it complete to track your study progress.