Layer 3: Network Layer
Routing & Logical Addressing
The Network Layer provides logical addressing and routing services to deliver packets from source to destination across multiple networks. It handles path determination and packet forwarding between different network segments.
Layer 3 (Network) Technologies
The Network Layer is responsible for end-to-end packet delivery across multiple networks. It provides logical addressing (IP), routing, path determination, and packet forwarding between different network segments.
The Critical Role: While Layer 2 handles local delivery using MAC addresses, Layer 3 enables global internet communication using IP addresses and routing protocols.
Source Host
Destination
Network Protocol Information
๐ฏ Primary Functions
- Logical Addressing: IP addresses for global device identification
- Routing: Finding best paths between networks
- Packet Forwarding: Moving packets toward their destination
- Path Determination: Calculating optimal routes
- Fragmentation: Breaking packets into smaller pieces when needed
๐ง Key Characteristics
- IP Addresses: 32-bit (IPv4) or 128-bit (IPv6) logical addresses
- Routing Tables: Databases of network paths
- Subnet Masks: Define network and host portions
- TTL/Hop Limit: Prevent infinite packet loops
- ICMP: Error reporting and network diagnostics
๐ Network Layer Protocols
๐ IPv4 (Internet Protocol v4)
Primary Internet Protocol
What you see in Wireshark: Source/destination IP addresses, TTL, protocol type
Every packet on the internet uses IP addressing๐ฎ IPv6 (Internet Protocol v6)
Next Generation Internet Protocol
What you see in Wireshark: 128-bit addresses, flow labels, hop limits
Solves IPv4 address exhaustion with massive address space๐ ICMP (Internet Control Message Protocol)
Network Diagnostics & Error Reporting
What you see in Wireshark: Ping requests/replies, error messages, network unreachable
Powers ping, traceroute, and network error reporting๐บ๏ธ OSPF (Open Shortest Path First)
Dynamic Routing Protocol
What you see in Wireshark: Hello packets, LSA updates, topology advertisements
Routers automatically learn network topology and calculate best paths๐ BGP (Border Gateway Protocol)
Internet Backbone Routing
What you see in Wireshark: Route advertisements, AS paths, network prefixes
How the global internet routes traffic between ISPs๐ ARP (Address Resolution Protocol)
IP to MAC Address Mapping
What you see in Wireshark: ARP requests/replies finding MAC addresses
Bridges the gap between Layer 2 (MAC) and Layer 3 (IP)๐ฆ IPv4 Packet Header Structure
Understanding what's inside every IP packet:
4 bits
4 bits
8 bits
16 bits
16 bits
3 bits
13 bits
8 bits
8 bits
16 bits
32 bits
32 bits
Key Header Fields Explained:
- TTL (Time to Live): Prevents packets from circling forever - decremented at each router
- Protocol: Tells what's inside (TCP=6, UDP=17, ICMP=1)
- Source/Dest IP: Where packet came from and where it's going
- Fragmentation: Allows large packets to be split across smaller networks
- Checksum: Detects errors in the header (not the data)
๐บ๏ธ How Routing Works
Scenario: Packet travelling from your home (192.168.1.100) to Google (8.8.8.8)
| Hop | Router | Network | Action | TTL |
|---|---|---|---|---|
| 1 | Home Router | 192.168.1.0/24 | Forward to ISP | 64 โ 63 |
| 2 | ISP Gateway | 10.0.0.0/8 | Route to backbone | 63 โ 62 |
| 3 | Backbone Router | Core Internet | BGP path selection | 62 โ 61 |
| 4 | Google Router | 8.8.8.0/24 | Deliver to server | 61 โ 60 |
๐ข Subnetting Mastery: Complete Guide โ Understanding how networks are divided and organised
๐ IP Address Structure Breakdown
๐ Working Example: 192.168.1.100/24
๐ Step 1: Identify the Components
๏ฟฝ๏ธ Host IP Address
๐ฏ Subnet Mask
๐ข Step 2: Convert to Binary
11000000.10101000.00000001.01100100
11111111.11111111.11111111.00000000
๐ฏ Step 3: Identify Network vs Host Portions
๐ Step 4: Calculate Network Details
๐ฏ Common Subnet Masks Reference
| CIDR | Subnet Mask | Total IPs | Usable Hosts | Binary Notation | Common Use Case |
|---|---|---|---|---|---|
| /8 | 255.0.0.0 | 16,777,216 | 16,777,214 | 11111111.00000000.00000000.00000000 | Class A / ISP Networks |
| /16 | 255.255.0.0 | 65,536 | 65,534 | 11111111.11111111.00000000.00000000 | Class B / Large Organisations |
| /24 | 255.255.255.0 | 256 | 254 | 11111111.11111111.11111111.00000000 | Class C / Small Office/Home |
| /25 | 255.255.255.128 | 128 | 126 | 11111111.11111111.11111111.10000000 | Subnet /24 into 2 |
| /26 | 255.255.255.192 | 64 | 62 | 11111111.11111111.11111111.11000000 | Subnet /24 into 4 |
| /27 | 255.255.255.224 | 32 | 30 | 11111111.11111111.11111111.11100000 | Small Department Networks |
| /28 | 255.255.255.240 | 16 | 14 | 11111111.11111111.11111111.11110000 | Tiny Networks (10-15 devices) |
| /30 | 255.255.255.252 | 4 | 2 | 11111111.11111111.11111111.11111100 | Point-to-Point Router Links |
| /31 | 255.255.255.254 | 2 | 2 | 11111111.11111111.11111111.11111110 | RFC 3021 P2P Links (no broadcast) |
| /32 | 255.255.255.255 | 1 | 1 | 11111111.11111111.11111111.11111111 | Single Host / Loopback |
๐งฎ Practical Subnetting Example
๐ Scenario
Your company has been assigned 192.168.10.0/24 and needs to create 4 separate subnets for different departments.
๐ Step 1: Calculate Required Bits
๐ฏ The Question:
How many bits do we need to borrow to create 4 subnets?
๐งฎ Formula: 2โฟ = Number of Subnets
๐ Subnet Mask Changes:
๐ข Step 2: Calculate Block Size
๐ฏ The Question:
How many IP addresses will each subnet contain?
๐งฎ Formula: 256 - Subnet Octet
๐ Each Subnet Provides:
๐ฏ Step 3: Subnet Breakdown
๐ข Sales Department
โ๏ธ Engineering Department
๐ข Marketing Department
๐ Administration Department
๐งฎ Visual Subnetting Calculator
Quick Reference: Common Subnet Divisions
Choose how many subnets you need from a /24 network
Block size: 128
Block size: 64
Block size: 32
Block size: 16
๐ Essential Subnetting Formulas
| Formula | Calculation | Purpose |
|---|---|---|
| Number of Subnets | 2^n (where n = borrowed bits) | How many subnets you can create |
| Hosts per Subnet | 2^h - 2 (where h = host bits) | Usable IP addresses per subnet |
| Block Size | 256 - subnet octet | Increment between subnets |
| Network Address | All host bits = 0 | First address (not usable) |
| Broadcast Address | All host bits = 1 | Last address (not usable) |
๐ก Real-World Subnetting Scenarios
๐ข Office Building Network
512 total addresses available
๐ญ Manufacturing Plant Network
65,536 total addresses available
๐ Wireshark Filters for Subnet Analysis
๐ Essential Network Filters
Copy these filters directly into Wireshark to analyse subnet traffic
๐ Real-World Example: Accessing a Website
Scenario: You type "www.google.com" in your browser
What happens at the Network Layer:
- DNS Resolution: Browser gets IP address (216.58.194.174) for www.google.com
- Route Lookup: Your router checks routing table for path to 216.58.194.174
- Packet Creation: HTTP request wrapped in IP packet with source/dest addresses
- Hop-by-Hop Forwarding: Each router decrements TTL and forwards toward destination
- Path Determination: Routers use OSPF/BGP to find best path
- Final Delivery: Packet reaches Google's network and is delivered
- Return Journey: Response follows same process in reverse
๐ Wireshark Network Layer Analysis
Step-by-step packet flow when accessing www.google.com
The Network Layer makes global internet communication possible by providing logical addressing and routing.
๐ Common Network Layer Problems
- Routing Loops: Packets circling between routers infinitely
- IP Address Conflicts: Multiple devices using same IP
- Subnet Misconfigurations: Wrong subnet masks preventing communication
- Routing Table Errors: Missing or incorrect routes
- MTU Problems: Packets too large for network segments
- TTL Expiration: Packets dying before reaching destination
๐ง Troubleshooting Tools
- Ping: Test basic connectivity and packet loss
- Traceroute: Show path packets take to destination
- Routing Tables: View and modify router forwarding tables
- IP Config: Display and configure IP settings
- Wireshark: analyse IP packet headers and routing
- Network Calculators: Subnet planning and IP management
๐ Teaching Analogy: Postal System
Think of the Network Layer like the postal system:
- Addresses (IP): Full mailing addresses that work globally
- Postal Codes (Subnets): Group addresses by geographic regions
- Sorting Facilities (Routers): Decide which direction mail should go
- Postal Routes (Routing Tables): Maps showing best paths to destinations
- Postal Trucks (Packets): Carry mail between sorting facilities
- Return to Sender (ICMP): Error messages when delivery fails
Just like the postal system routes mail across the world, Layer 3 routes packets across the internet!
๐ Key Learning Points
- Network Layer provides logical addressing that works across different networks
- Routers operate at Layer 3, making forwarding decisions based on IP addresses
- Routing protocols (OSPF, BGP) automatically learn and share network topology
- Subnetting allows efficient use of IP address space
- TTL/Hop Limit prevents packets from looping forever
- Layer 3 makes internet-scale communication possible