Addresses, CIDR blocks and the default gateway: DHCP, ARP and the next hop
Calculate IPv4 subnets using CIDR notation, evaluate routing boundaries with bitwise subnet masking, and trace local ARP resolution to default gateways.
Contentsand lesson path
On this page
- IPv4 Address Architecture and CIDR Subnet Math
- Determining the Next Hop: Local Link vs. Default Gateway
- Resolving MACs and Bootstrapping: ARP and DHCP
- Check your understanding
- Apply it
- Review prompt
Lessons of Networking Basics
- Layers as a debugging map, and what L4 and L7 mean Concept · 15 min
- Addresses, CIDR blocks and the default gateway: DHCP, ARP and the next hop Worked example · 25 min
- From a name to a response: DNS, TCP and HTTP in one trace Worked example · 20 min
- Ports, NAT, firewalls, proxies and TLS along the path Concept · 20 min
- Troubleshooting lab: which hop is broken? Lab · 25 min
- Check: subnetting and failure triage Knowledge check · 8 questions
What you will learn
- Calculate address ranges from CIDR notation and decide whether two hosts can reach each other directly or need a router.
01. IPv4 Address Architecture and CIDR Subnet Math
Every IPv4 address is a 32-bit integer typically expressed in human-readable dotted-decimal notation consisting of four 8-bit octets (ranging from 0 to 255, separated by periods). In historical networking, addresses were divided into rigid classes (Class A, B, and C). Today's Internet and cloud networks use Classless Inter-Domain Routing (CIDR, defined in RFC 4632) instead.
CIDR notation appends a slash followed by a prefix length (/prefix) indicating how many high-order bits represent the network identity, leaving the remaining bits to identify unique host interfaces:
- Total addresses: 2 to the power of (32 − prefix). A
/24leaves 8 host bits, so 2^8 = 256 addresses. - Usable host addresses on a classic LAN: the total minus 2, because the first address identifies the network itself and the last one is the subnet broadcast address. (
/31and/32are special cases: RFC 3021 allows both addresses of a/31on point-to-point links.)
Dotted-decimal subnet masks correspond directly to CIDR prefixes. For example, a /24 prefix corresponds to mask 255.255.255.0 (24 consecutive binary ones followed by 8 zeroes). A /21 prefix corresponds to mask 255.255.248.0 (21 binary ones followed by 11 zeroes).
Common CIDR blocks encountered in DevOps architectures include:
/32: Exactly 1 address (2^0). Represents a specific single host or container interface./28: 16 addresses (2^4), with 14 usable hosts. Frequently used for tiny database clusters or bastion subnets./24: 256 addresses (2^8), with 254 usable hosts (.1through.254). A common size for one application subnet./22: 1,024 addresses (2^10), covering exactly four contiguous/24blocks. For example,10.96.8.0/22spans from10.96.8.0through10.96.11.255inclusive./16: 65,536 addresses (2^16), a common size for a whole cloud VPC (e.g.10.100.0.0/16)./0: The default route (0.0.0.0/0), matching all remaining traffic across the entire Internet.
Worked problem. A host has the address 172.20.37.200/21. It needs to talk to two machines, 172.20.33.14 and 172.20.40.9. Which one can it reach directly on its own subnet, and which one needs the default gateway? Work it out in five steps.
- Write the mask.
/21means 21 one-bits: 8 + 8 + 5. The first two octets are all ones (255.255). The third octet has five ones and three zeros,11111000, which is 248. The last octet is all zeros. The mask is255.255.248.0. - Find the block size. The mask ends inside the third octet, which keeps 3 host bits, so subnets step by 2^3 = 8 in that octet:
172.20.0.0,172.20.8.0,172.20.16.0,172.20.24.0,172.20.32.0,172.20.40.0and so on. A quick way to get the step: 256 − 248 = 8. - Find the network address. Take the largest multiple of 8 that is not above 37: that is 32, so the network is
172.20.32.0/21. This is the same as the bitwise AND that the kernel does: 37 is00100101, AND11111000gives00100000, which is 32. - Find the broadcast address and the usable range. The next block starts at
172.20.40.0, so this block ends just before it: the broadcast address is172.20.39.255. The block has 2^(32 − 21) = 2^11 = 2,048 addresses. Without the network and broadcast addresses, the usable hosts are172.20.32.1to172.20.39.254, which is 2,046 addresses. - Decide for each machine.
172.20.33.14lies between172.20.32.0and172.20.39.255, so it is on the same subnet: the host sends an ARP request for172.20.33.14and delivers the frame directly. For172.20.40.9, the third octet 40 AND 248 is 40, so its network would be172.20.40.0, the next block. It is not on-link, so the packet goes to the default gateway.
Notice the trap: 172.20.33.14 has a different third octet from 172.20.37.200 (33, not 37) and is still on the same subnet. You can compare octets by eye only when the prefix is a multiple of 8 (/8, /16, /24). For any other prefix, work out the block first. Python's ipaddress module does the same calculation and is a good way to check your answer:
python3 - <<'EOF'
import ipaddress
net = ipaddress.ip_interface("172.20.37.200/21").network
print("mask ", net.netmask)
print("network ", net.network_address)
print("broadcast", net.broadcast_address)
print("usable ", net.num_addresses - 2)
for other in ["172.20.33.14", "172.20.40.9"]:
where = "on-link" if ipaddress.ip_address(other) in net else "via gateway"
print(other, where)
EOFmask 255.255.248.0
network 172.20.32.0
broadcast 172.20.39.255
usable 2046
172.20.33.14 on-link
172.20.40.9 via gateway02. Determining the Next Hop: Local Link vs. Default Gateway
When an operating system kernel prepares to transmit an IP packet, it executes a fundamental binary decision: Is the destination IP located on my local physical subnet, or does it require a router?
The kernel answers it with one lookup in its routing table: it picks the most specific route that matches the destination (longest-prefix match). Configuring an address such as 10.0.1.5/24 on eth0 automatically adds a connected route, 10.0.1.0/24 dev eth0 proto kernel scope link, which is the routing-table form of "same subnet" (destination & netmask == local_ip & netmask):
- Direct Local Link Delivery: If the winning route has no
via(a connected route,scope link), the destination is on the same broadcast domain. The kernel sends the packet directly to the destination host, encapsulated in a Layer 2 Ethernet frame addressed to that host's MAC. - Indirect Gateway Delivery: If the winning route has
via <gateway_ip>, usually thedefaultroute, the target is on another network. The kernel forwards the packet to that router for onward transit.
ip route get <ip> shows which route wins. On a host with 192.168.225.201/24, ip route get 192.168.225.7 prints 192.168.225.7 dev eno1 src 192.168.225.201 (no via: deliver directly), while ip route get 8.8.8.8 prints 8.8.8.8 via 192.168.225.1 dev eno1 ... (send to the gateway).
Without a matching routing entry or a default route, the kernel rejects the packet at once with the error Network is unreachable, and nothing is sent on the network.
# Inspect IP addresses and subnet masks across active interfaces
ip -br addr show
# Display kernel routing table with default gateway destination
ip route show
# Query kernel route decision for a specific target IP
ip route get 8.8.8.803. Resolving MACs and Bootstrapping: ARP and DHCP
IP routing operates at Layer 3, but physical Ethernet switches deliver frames at Layer 2 using 48-bit Media Access Control (MAC) addresses. Before a host can send an IP packet onto the local network segment, it must translate the target IPv4 address into a destination MAC address using the Address Resolution Protocol (ARP):
- ARP Request: The sender broadcasts an Ethernet frame (
FF:FF:FF:FF:FF:FF) asking: "Who has IP 192.168.1.1? Tell 192.168.1.50". Every device on the local switch hears this broadcast. - ARP Reply: The host owning that specific IP unicasts a reply containing its hardware MAC address (
52:54:00:12:34:56). - ARP Cache: The sender stores this mapping in its kernel neighbour table (
ip neigh show) and reuses it for later packets. Linux re-checks an entry that has not been confirmed for a while (tens of seconds by default) instead of broadcasting before every packet.
One rule follows from the routing decision: when the route to a remote address such as 8.8.8.8 goes via a gateway, the host does not ARP for 8.8.8.8 at all. It sends an ARP request for the default gateway's MAC address and puts the packet for 8.8.8.8 inside an Ethernet frame addressed to the gateway.
In high-availability failover architectures (such as Keepalived or VRRP virtual router failover), a backup server that takes over a virtual IP emits a Gratuitous ARP (GARP) broadcast. This notifies all switches and neighboring servers to update their ARP caches immediately with the new MAC address without waiting for stale cache entries to time out.
When a VM or physical server boots with dynamic addressing, it acquires its IP address, subnet mask, default gateway, and DNS resolvers using the Dynamic Host Configuration Protocol (DHCP) via a four-step DORA handshake: Discover (client broadcast), Offer (server response), Request (client selection), and Acknowledge (server lease confirmation). Not every machine uses DHCP: many servers have static or cloud-init configuration, and containers usually get their address from the container runtime (Docker IPAM) or the Kubernetes CNI plugin.
04. Check your understanding
05. Apply it
Apply these IP networking best practices when architecting cloud infrastructure:
- Size Cloud Subnets with Growth Headroom: Allocate at least
/20or/16CIDR blocks for production Kubernetes clusters. With VPC-native CNIs (such as the AWS VPC CNI or GKE VPC-native clusters) every pod takes a VPC address. Running out later means adding a secondary CIDR block and new subnets, or switching to prefix delegation, which is disruptive work, so plan the space up front. - Verify Default Routes on New Hosts: If a server can reach local subnet peers but cannot reach the Internet or download packages, execute
ip route showimmediately. If thedefault via <ip>line is missing, add it viasudo ip route add default via <gateway_ip> dev <interface>. That fixes it only until the next reboot, DHCP renewal ornetplan apply: make it permanent in the host's network configuration (netplan, NetworkManager or the cloud DHCP options) and find out why the route was missing. - Inspect Neighbor Tables for IP Conflicts: If connectivity to a local server is intermittent, inspect
ip neigh show. Two devices claiming the same IP will cause flapping MAC entries in the ARP table.
06. Review prompt
Explain how CIDR prefix lengths dictate the number of usable host addresses in an IPv4 network. Describe the bitwise AND operation performed by a host to decide whether to send a packet directly or forward it to a default gateway. Detail the step-by-step role of ARP when transmitting data to a server located outside the local subnet.
References
Your progress
Reading state
Sign in to save that you finished reading this lesson.
Prove this skill
8 questions · about 6 minutes · scored automatically. Marking a lesson as read never demonstrates a skill.