IP Addressing, Subnetting and Routing
Work with IPv4 and IPv6 addresses, CIDR and subnet masks, private ranges and NAT, DHCP, and the basics of how routers choose paths.
Intermediate · about 5 hours · difficulty 3/5
Learn first: How the Internet Works: OSI and TCP/IP
The network layer gets packets from one machine to any other machine on the internet. Subnetting numericals are standard in aptitude-style CS tests, and NAT and DHCP explain everyday networking behaviour.
IPv4 and CIDR
- An IPv4 address is 32 bits, written as four octets (
192.168.1.10). - CIDR notation
/24means the first 24 bits are the network part. A /24 has 256 addresses, 254 usable hosts (network and broadcast addresses are reserved). - Subnetting: borrowing host bits to split a network. Practise questions like "divide 10.0.0.0/24 into 4 subnets" (four /26 blocks of 64) and "which subnet does this IP belong to" by ANDing with the mask.
- Classful addressing (A, B, C) is legacy but still appears in some tests.
Private addresses and NAT
- Private ranges:
10.0.0.0/8,172.16.0.0/12,192.168.0.0/16. They are not routable on the public internet. - NAT lets many private devices share one public IP by rewriting addresses and ports at the router. It is why your laptop's IP is different from what websites see.
- DHCP hands out IP, subnet mask, gateway and DNS server automatically (Discover, Offer, Request, Acknowledge).
IPv6
128-bit addresses written in hex, no need for NAT, simplified header. Know the shorthand (::) and why IPv6 exists (IPv4 exhaustion).
Routing
- Routers forward using a routing table and longest prefix match.
- Interior routing: distance vector (RIP, Bellman-Ford based) vs link state (OSPF, Dijkstra based). You already know both algorithms from graphs.
- BGP connects autonomous systems across the internet (optional depth).
- ICMP powers
pingandtraceroutevia TTL expiry.
Good enough to move on: you can compute network address, broadcast address and host range for any IP and prefix, and explain NAT to a friend.
Key concepts
- IPv4 structure and CIDR
- Subnet masks and subnetting numericals
- Private ranges and NAT
- DHCP
- IPv6 basics
- Routing tables and longest prefix match
- RIP vs OSPF
- ICMP, ping and traceroute
- BGP overview
Mini project
Write a subnet calculator CLI that takes an IP in CIDR notation and prints the network address, broadcast address, usable host range and host count, and can split a block into N equal subnets. Verify a few outputs with traceroute and ipconfig/ip addr on your machine.
Check yourself
How many usable hosts does 172.16.5.0/27 have, what is its broadcast address, and does 172.16.5.40 belong to it?
Free resources
- Cloudflare Learning Center: What is a subnet? (Cloudflare)
- Cloudflare Learning Center: What is NAT? (Cloudflare)
- Kurose and Ross: Network layer resources (Kurose and Ross)