NetwNETW
Curriculum
CHAPTER 05

Network Layer

IP addressing, subnetting, routing, ICMP

16 min read10 sections
In this chapter
IPAnatomy of an IP packetHow a packet actually movesWhy a default gateway is neededWhy subnetting existsSubnet calculatorRoutingRouting protocolsICMPIPv6 and why IPv4 ran out

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.

Why this exists

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.

Think: If a router only needed the destination address, why does the header carry a source address too?

Inside an IPv4 packet

Click a field to see what it does.

20-byte header
DATA (TCP segment or UDP datagram)
Destination address32 bits

Where the packet must go. Routers forward based on this field.

How a router uses the destination address
packet arrives→read destination→match routing table→TTL − 1→forward

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.

Think: Why would changing the IP address at every hop break the internet?

How an IP packet travels

The IP addresses stay the same. The link addresses change at every hop.

Source IP
192.168.1.10
Destination IP
93.184.216.34
TTL at this hop
64

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.

Why this exists

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.

Think: The frame's destination MAC is the gateway, but the packet's destination IP is the server. Why are they different?

Why you need a default gateway

The gateway is only used when the destination is outside your subnet.

destination192.168.1.20mask /24
1Your PC wants 192.168.1.20.
2It compares the destination with its own subnet mask. Same network.
3It ARPs for 192.168.1.20 and gets the device's MAC.
4The frame goes directly to that device. No gateway involved.

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.

Why this exists

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.

/24
1
1
0
0
0
0
0
0
1
0
1
0
1
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
1
0
1
0
network part
host part
Network
192.168.1.0
Mask
255.255.255.0
Usable hosts
254

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

/24
Mask
255.255.255.0
Host bits
8
Total addrs
256
Usable hosts
254

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.

Why this exists

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.

Check your understanding
0 / 1 correct
Which routing principle picks the most specific route?