learninfra · Linux · Networking · Kubernetes · System Design · AI Infrastructure · Exam blueprints · Drills

IP, Subnets & CIDR

An address is a network number and a host number. The mask decides which is which, and every host uses it to choose between a neighbour and a router.

An interactive Networking lesson: 21 steps, about 30 minutes, on a live simulation in your browser.

A small office: three desks, pc1, pc2 and pc3, plugged into one switch. A router, gw, leads to a second network where the file server nas lives. Leave that side alone for a minute.

pc1 pings pc2 at 192.168.1.11. Watch what travels. First an ARP broadcast, the question that turns an IP address on your own LAN into the hardware (MAC) address behind it. Then the ping itself, straight through the switch. The router took no part in delivering it.

What you will learn

  1. An address has two halves

    • Two machines, one wire
    • An address is 32 bits: An IP address is a network number and a host number glued together. The prefix length says where the join is.
    • Mask, prefix and ip addr: Mask and prefix are one fact in two spellings: /24 is 255.255.255.0. Address AND mask gives the network.
  2. Neighbour or stranger?

    • The question before every packet: Same network after masking: deliver it yourself and ARP for the destination. Different network: hand it to a router.
    • Break it: a stranger and no gateway
    • Whose MAC address?: Traffic for another network goes to the gateway's MAC address, with the final destination's IP address still inside.
    • Two addresses, two jobs: The IP header says where the packet is going in the end. The Ethernet header says only where it is going next.
    • Drill: add a default gateway
  3. Network, broadcast, hosts

    • Two addresses you cannot use: All-zero host bits name the network, all-one host bits address everyone on it. Hosts get what is in between: 2^h − 2.
    • Count the hosts in a /26
    • Where a /26 starts and ends: Block size is 256 minus the mask byte. Networks start at multiples of the block size; the broadcast is one below the next start.
    • Which network is .70 in?: Two addresses that look close can sit in different networks. Only the mask decides.
    • The ladder from /30 to /8
  4. Wrong mask, wrong answer

    • Break it: the wrong mask
    • Why /16 gave the wrong answer: Read who sent the "unreachable". Your own address means ARP failed on your LAN. A router's address means the packet got that far.
    • Reading ip route: The connected route is the mask written as a route: this prefix is on my wire. The default route is: everything else goes to that router.
    • Drill: ask the kernel
  5. Private ranges

    • Addresses anyone may use: A private address is unique only inside its own network. The internet has no routes for 10/8, 172.16/12 or 192.168/16.
    • Inside 172.16.0.0/12 or not?
  6. Recap & playground

    • Cheat sheet
    • Playground