Network Layer
IP addressing, subnetting, routing, ICMP
01IP
Layer 3 provides logical addressing and routing across networks. IPv4 (32-bit) and IPv6 (128-bit). IP is connectionless and best-effort; reliability is TCP's job.
A network cable only reaches one link. To send data across many networks you need a common address that every network understands, and a way to decide which direction to send it. That is what IP is for. Without it, each link would need its own incompatible addressing scheme and the internet could not exist.
- ▸IPv4: 4 octets, e.g. 192.168.1.10
- ▸IPv6: 8 groups of hex, e.g. 2001:db8::1
- ▸TTL prevents infinite loops
- ▸Protocol field: 6=TCP, 17=UDP, 1=ICMP
02Anatomy of an IP packet
Every IP packet starts with a header. The destination address tells routers where it must go. TTL stops it from looping forever. The protocol field says what is inside.
Inside an IPv4 packet
Click a field to see what it does.
Where the packet must go. Routers forward based on this field.
03How a packet actually moves
The source and destination IP addresses stay the same for the whole journey. At every hop the router removes the old link header and adds a new one for the next link. This is why IP is called end-to-end while Ethernet is hop-by-hop.
How an IP packet travels
The IP addresses stay the same. The link addresses change at every hop.
Builds packet: src 192.168.1.10, dst 93.184.216.34. Sends to gateway.
04Why a default gateway is needed
A host can only put frames on its own link. If the destination IP is outside its subnet, it cannot reach it directly. The default gateway is the router on the local network that agrees to carry those packets onward. The host sends the frame to the gateway's MAC address while the packet still names the far destination IP.
Without a gateway, a computer could only talk to devices on its own cable or Wi-Fi. The gateway is the single door out, and it is the reason a home network can reach the whole internet with one router.
Why you need a default gateway
The gateway is only used when the destination is outside your subnet.
05Why subnetting exists
A subnet mask splits an IP into network + host portions. CIDR notation (/24) replaces classful addressing. Subnetting creates smaller broadcast domains and conserves addresses.
If every device shared one giant network, every broadcast would reach every machine and every problem would affect everyone. Subnets split one address block into smaller, manageable groups: a floor, a department, a server rack. The mask is how a device decides whether the destination is next door or must go through a gateway.
192.168.1.0/24 -> 256 addresses, 254 usable 192.168.1.0/26 -> 64 addresses, 62 usable 10.0.0.0/8 -> 16,777,216 addresses
How a subnet splits an address
192.168.1.10, drag the prefix length.
The first 24 bits identify the network. The rest identify the device. A larger prefix means fewer devices per subnet.
06Subnet calculator
Drag to see how prefix length affects host count and mask.
Subnet Calculator
07Routing
Routers consult routing tables (static or dynamic: OSPF, BGP, IS-IS). Longest prefix match selects the best route. Packets hop router-by-router; TTL decrements each hop.
Packet Routing, Hop by Hop
Step 1/6: packet at You. Each router decrements TTL and picks next hop by longest prefix match.
08Routing protocols
Interior (OSPF, IS-IS, EIGRP) within an AS; exterior (BGP) between ASes. BGP is the protocol that holds the internet together and is why a route can be hijacked.
09ICMP
Internet Control Message Protocol: ping (echo), traceroute (TTL expiry), destination unreachable, redirect. Not for user data; used for diagnostics and signaling.
10IPv6 and why IPv4 ran out
IPv4 has 32-bit addresses, about 4.3 billion. That sounded endless in 1981 and was not. NAT and subnetting stretched it, but the real fix is IPv6: 128-bit addresses, enough for every device many times over. IPv6 also removes the need for NAT and simplifies the header.
Every phone, laptop, camera and sensor needs an address. IPv4 simply does not have enough. IPv6 is not a feature, it is the long-term replacement for the address space itself.