{}DSA Atlas

IP Addressing, Subnetting & Routing

IPv4 and IPv6 addressing, CIDR and subnetting worked step by step (including VLSM), private ranges, ARP, DHCP, NAT/PAT, longest-prefix-match routing, OSPF vs BGP, ICMP/ping/traceroute, MTU and fragmentation, and cloud VPC networking.

Beginner → Intermediate8 interview questions

IPv4 addresses

A 32-bit number written as four octets: 203.0.113.42. It has a network part and a host part, separated by the prefix length (CIDR notation /24) or subnet mask (255.255.255.0).

Special ranges

RangePurpose
10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16private (RFC 1918)
100.64.0.0/10carrier-grade NAT shared space
127.0.0.0/8loopback (localhost)
169.254.0.0/16link-local (no DHCP); cloud metadata service at 169.254.169.254
0.0.0.0/0"everything" — the default route
224.0.0.0/4multicast
255.255.255.255limited broadcast

Subnetting, step by step

Formulas for prefix length p:

  • addresses in the subnet = 2^(32 − p)
  • usable hosts = 2^(32 − p) − 2 (network + broadcast addresses; cloud providers reserve more, e.g. AWS reserves 5 per subnet)
  • block size in the "interesting" octet = 256 − mask value in that octet
PrefixMaskAddressesUsable hosts
/24255.255.255.0256254
/25255.255.255.128128126
/26255.255.255.1926462
/27255.255.255.2243230
/28255.255.255.2401614
/30255.255.255.25242 (point-to-point links)
/16255.255.0.065,53665,534

Example 1: which subnet is 192.168.10.77/26 in?

.0 – .63 .64 – .127 .128 – .191 .192 – .255 /26 → block size 64 in the last octet .77 lives here network .64 · hosts .65–.126 · broadcast .127
Find the block that contains the address.

In binary: 77 = 01001101. A /26 keeps the first 2 bits of the last octet (01) → network 01000000 = 64; broadcast 01111111 = 127.

Example 2: VLSM — carve 10.0.5.0/24 for 100, 50 and 20 hosts

Allocate the largest first:

NeedSmallest fitting prefixSubnetUsable rangeBroadcast
100 hosts/25 (126)10.0.5.0/25.1 – .126.127
50 hosts/26 (62)10.0.5.128/26.129 – .190.191
20 hosts/27 (30)10.0.5.192/27.193 – .222.223
spare/2710.0.5.224/27.225 – .254.255

Example 3: are two hosts on the same subnet?

10.1.4.20/22 and 10.1.7.200/22: /22 → block 4 in the third octet (blocks 0, 4, 8, …). Both third octets (4 and 7) are in the 4–7 block → same subnet 10.1.4.0/22 (hosts 10.1.4.1 – 10.1.7.254).

Python
import ipaddress

net = ipaddress.ip_network("192.168.10.77/26", strict=False)
print(net, net.netmask, net.broadcast_address, net.num_addresses - 2)
# 192.168.10.64/26 255.255.255.192 192.168.10.127 62
print(list(ipaddress.ip_network("10.0.5.0/24").subnets(new_prefix=26)))

IPv6 in brief

  • 128-bit addresses: 2001:0db8:0000:0000:0000:ff00:0042:8329 → 2001:db8::ff00:42:8329.
  • Typical allocation: /48 to a site, /64 per subnet (SLAAC requires /64).
  • Types: global unicast (2000::/3), link-local (fe80::/10), unique local (fc00::/7), multicast (ff00::/8), loopback ::1.
  • No broadcast; Neighbor Discovery (ICMPv6) replaces ARP; routers don't fragment.

ARP and DHCP

Client DHCP server DISCOVER (broadcast) OFFER 192.168.1.23, mask, gateway, DNS, lease REQUEST 192.168.1.23 (broadcast) ACK
DORA: Discover, Offer, Request, Acknowledge.

ARP then resolves the gateway's IP to its MAC so the host can send frames off-subnet.

NAT and PAT

10.0.0.5:51000 10.0.0.9:51000 NAT router203.0.113.7 93.184.215.14:443 translation table: 10.0.0.5:51000 ↔ 203.0.113.7:62001 10.0.0.9:51000 ↔ 203.0.113.7:62002
Many private hosts share one public IP; ports keep the flows apart.

Routing

  • Longest prefix match chooses the most specific route.
  • Interior protocols (within an organisation): OSPF, IS-IS (link-state: every router knows the topology and runs Dijkstra), RIP (distance vector, legacy).
  • Exterior: BGP between autonomous systems (ISPs, clouds, large companies). Path-vector, policy-driven. BGP misconfigurations or hijacks have taken down large parts of the internet (Facebook's 2021 outage withdrew its own routes, making its DNS unreachable).
  • Anycast: the same IP announced from many locations; BGP sends users to the nearest — used by DNS root servers, CDNs and DDoS protection.

ICMP, ping and traceroute

  • ping sends ICMP Echo Request/Reply → reachability and RTT.
  • traceroute exploits TTL expiry to list hops.
  • ICMP "Destination Unreachable", "Time Exceeded", "Fragmentation Needed" carry essential signals — don't block all ICMP.

MTU and fragmentation

Ethernet MTU 1500 B → TCP payload (MSS) ≈ 1460 B. Tunnels (VPN, VXLAN, GRE, IPsec) add headers and shrink the effective MTU. Blocked ICMP → PMTUD black holes: TCP handshakes and small requests succeed but large transfers hang.

Cloud networking (VPC) — what system designs assume

ConceptMeaning
VPC / VNetyour private network in the cloud, with a CIDR like 10.0.0.0/16
Subnetsper availability zone; public (route to an internet gateway) or private (outbound via NAT gateway)
Route tableswhere traffic goes (local, IGW, NAT GW, peering, transit gateway)
Security groupsstateful, per-instance allow rules
Network ACLsstateless, per-subnet allow/deny rules
Load balancerspublic LB in public subnets → app servers in private subnets
Private endpointsreach managed services (S3, databases) without the internet
Peering / transit gateway / VPN / Direct Connectconnect VPCs and on-prem networks

Interview questions

0 / 8 marked confident

Answer out loud first, then open the model answer. Mark a question confident only when you could explain it to an interviewer without notes.