Knowledge
IPv4: subnets and CIDR
Estimated time: 50 minutes.
Quick summary
-
IP Class A
- Value: 1.0.0.0 – 126.255.255.255 (first octet: 1–126)
- Why: RFC 791 §3.2 defines classful addressing: Class A has high-order bit=0, an 8-bit network ID (first octet 1–126) and 24 host bits — each Class A block contains 2²⁴−2 = 16,777,214 usable hosts. Allocating an entire Class A /8 to a single organization is characteristic of the classful era before CIDR; today there are no unallocated Class A addresses left.
- When it breaks: Mistaking 127.x.x.x for Class A → misconfiguration. 127.0.0.0/8 is loopback (localhost), not an ordinary Class A. Also, handing an entire /8 to one organization wastes IPs → this is the reason CIDR was created to replace classful addressing.
- In real deployments: Today almost nobody is allocated a whole Class A. Still, you need to recognize it: 10.0.0.0/8 (private Class A) is very common in AWS/GCP VPCs. When you see a 10.x.x.x IP, you know right away it is a private Class A range.
-
IP Class B
- Value: 128.0.0.0 – 191.255.255.255 (first octet: 128–191)
- Why: RFC 791 §3.2 defines Class B as having high-order bits=10, a 16-bit network ID (first octet 128–191) and 16 host bits — each Class B block contains 2¹⁶−2 = 65,534 usable hosts. The range 172.16.0.0–172.31.255.255 belongs to Class B but is reserved for private use by RFC 1918 §3 — it is not routed on the internet.
- When it breaks: Mistaking 172.16.x.x – 172.31.x.x for public Class B → exposing internal services to the internet. The 172.16.0.0/12 range is private per RFC 1918 and is not routed on the internet. Check carefully before opening the firewall.
- In real deployments: 172.16.0.0/12 (private Class B) is commonly used for VPNs and office networks. Docker's default 172.17.0.0/16 also falls within this range → it easily conflicts with an office VPN. When designing a network, avoid overlapping with common ranges.
-
IP Class C
- Value: 192.0.0.0 – 223.255.255.255 (first octet: 192–223)
- Why: RFC 791 §3.2 defines Class C as having high-order bits=110, a 24-bit network ID (first octet 192–223) and 8 host bits — each Class C block contains 2⁸−2 = 254 usable hosts. Class C is only an address range; CIDR allows splitting it smaller than /24 (VLSM) or merging several /24s into a supernet — Class C does not mean /24.
- When it breaks: Always assuming Class C = /24 → not understanding VLSM. Class C is only an address range; it can be split smaller than /24 (such as /26, /28) or merged into something larger (/23, /22). Don't confuse classful addressing with CIDR.
- In real deployments: 192.168.0.0/16 (private Class C) is the default range of home/SMB routers. When developing and testing locally, 192.168.1.x is common. In the cloud, avoid 192.168.1.0/24 because it easily conflicts with your home network when you use a VPN.
-
IP Class D & E
- Value: D: 224–239 (multicast), E: 240–255 (reserved)
- Why: Class D (224.0.0.0 – 239.255.255.255) is for multicast — sending 1 packet to many hosts that have subscribed to receive it (video streaming, the OSPF routing protocol). Class E (240.0.0.0 – 255.255.255.255) is reserved for research.
- When it breaks: Assigning a Class D/E IP to a host → the network does not work. These are special addresses, not used for ordinary unicast. If you see a 224.x.x.x IP in a config → it is completely wrong.
- In real deployments: Multicast is used inside datacenters (VXLAN, PIM). Developers rarely need to configure it directly. Know it so you can recognize it when debugging with tcpdump: traffic to 224.0.0.x is a multicast protocol, not an attack.
-
Private vs Public IP
- Value: Private: internal, not routed on the internet. Public: global, unique.
- Why: RFC 1918 §3 defines 3 private address ranges that are not routable on the internet: 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16. Any organization can use these ranges without registering — they are not globally unique. A host in a private range that wants to reach the internet must go through NAT.
- When it breaks: Exposing a private IP to the internet (a wrong firewall rule) → nobody outside the LAN can reach it because private IPs are not routed on the internet. Conversely, using public IPs for internal services → costs money + is a security risk.
- In real deployments: AWS/GCP: an EC2/VM has a private IP (10.x.x.x) + can have a public IP attached (Elastic IP). Traffic between EC2 instances in a VPC uses private IPs (free, low latency). Traffic out to the internet uses public IPs (charged, through a NAT Gateway).
-
NAT (Network Address Translation)
- Value: Rewrites the source IP from private → public when going out to the internet
- Why: RFC 3022 defines NAT (Network Address Translation): a router/firewall replaces the source IP in the IP header from private → public as the packet leaves for the internet; when the reply comes back, NAT looks up its table to translate the destination IP back to the original private address. When you curl from a laptop to the internet, the server log records the public IP of the NAT gateway — not the laptop's private IP.
- When it breaks: Not understanding NAT → you cannot debug "why does the server see a different IP from my machine's IP". When you curl from a laptop, the server log records the IP of the NAT gateway (the home/company router), not the laptop's IP. Check with ipinfo.io.
- In real deployments: AWS NAT Gateway lets a private subnet reach the internet. It costs about $0.045/GB of data processed. Kubernetes LoadBalancer uses SNAT so that pods reply to the correct client. Docker port mapping (-p 80:3000) is also a form of NAT (DNAT).
-
Network address
- Value: All host bits are 0
- Why: Like the street number of an entire apartment building — it represents the whole subnet. Routers use this address to find the path. It is not assigned to a specific machine.
- When it breaks: Assigning the network address to a host → ARP conflict, routing chaos. Every packet sent to the network address is treated as sent to "the whole subnet" in the routing sense, not to one specific machine.
- In real deployments: When you create a subnet in an AWS VPC or a Docker network, the first address (.0) is always the network address — it cannot be assigned to an EC2 instance or container. AWS also reserves the first 4 IPs and the last 1 IP of every subnet.
-
Broadcast address
- Value: All host bits are 1
- Why: Like a building's loudspeaker — it sends a message to every machine in the subnet at once. It is used when you need to ask "who has this MAC?" (ARP) or "is there a DHCP server?" (DHCP). It is not assigned to a specific machine.
- When it breaks: Broadcast storm: if many machines send broadcasts continuously → every NIC in the subnet has to process them → CPU spikes everywhere at once. This is why the broadcast domain must be limited; small subnets help contain broadcasts.
- In real deployments: Understanding broadcast helps explain why in Docker/K8s each pod/container needs its own small subnet — to reduce broadcast traffic. Cloud VPCs usually disable broadcast entirely and use unicast ARP instead.
-
Subnet mask
- Value: A bit string with 1s for the network part and 0s for the host part
- Why: Like a cookie cutter — it masks the network part and reveals the host part. A machine uses the mask to know: "is that IP on the same network as mine?" If yes → send directly. If not → go through the gateway.
- When it breaks: A wrong subnet mask on a host → the host thinks the destination IP is on the same LAN when it is actually on another network (it sends ARP instead of going through the gateway) or the other way around → all traffic is dropped. This is a common configuration error when setting up a VPS manually.
- In real deployments: When configuring a static IP on a VPS: ip addr add 10.0.0.5/24 dev eth0. The /24 that follows is the subnet mask. Get this number wrong = the VPS cannot talk to its gateway = you lose SSH immediately.
-
Wildcard mask
- Value: The bit-inverse of the subnet mask
- Why: RFC 4632 §3 defines CIDR (Classless Inter-Domain Routing): addresses are written in address/prefix-length notation, where the prefix-length is the number of bits reserved for the network part. /24 means the first 24 bits are the network and the remaining 8 bits are the host — completely replacing the classful A/B/C concept. CIDR allows any prefix from /0 to /32.
- When it breaks: Confusing the subnet mask and the wildcard mask in a Cisco ACL → allows the wrong traffic or blocks the right traffic. It is very hard to debug because the ACL takes effect immediately and this error gives no clear error message.
- In real deployments: Rarely seen in modern cloud (AWS/GCP use CIDR notation), but you still run into it when configuring IPsec VPNs or integrating with a company's Cisco devices.
-
CIDR /n
- Value: n network bits at the start
- Why: A shorthand for the subnet mask. /24 means the first 24 bits are for the network and the remaining 8 bits are for hosts. It replaces the old Class A/B/C — letting you divide a network flexibly to fit real needs.
- When it breaks: Not understanding CIDR → you cannot design a VPC subnet yourself and always have to ask someone else. When the /n is wrong (for example /25 instead of /24) → the network is split in half and you do not know why two machines cannot ping each other.
- In real deployments: Every cloud provider uses CIDR: AWS VPC CIDR, GCP subnets and Azure VNets all require CIDR notation. You need to pick the right /n so there are enough IPs for the expected number of instances, with a buffer for later growth.
-
Usable hosts
- Value: 2^(32−n) − 2
- Why: The number of machines that can actually be assigned an IP in the subnet. You must subtract 2: the first (network) and last (broadcast) addresses are not assigned to machines. E.g. /24 has 256 addresses, usable = 254.
- When it breaks: Miscalculating usable hosts → choosing a subnet that is too small → running out of IPs when you scale → having to re-IP the entire system, which is extremely laborious. AWS also subtracts 5 reserved IPs per subnet, which must be factored into the plan.
- In real deployments: Rule of thumb: choose a subnet with at least 2x the number of hosts you currently need. If you need 50 servers, choose /25 (126 usable) rather than /26 (62 usable). Re-subnetting in the cloud is painful — plan ahead from the start.
-
Private ranges
- Value: 10/8, 172.16/12, 192.168/16
- Why: 3 "internal" IP ranges anyone may use — no registration needed. Used in companies, homes, Docker, VPCs. To reach the internet they must go through NAT (translated into a public IP).
- When it breaks: Using a private range that overlaps with a VPN or office network → IP conflict → the VPN cannot connect or traffic is routed to the wrong place. Docker uses 172.17/16 by default — which often conflicts with an office's 172.16/12.
- In real deployments: When creating a Docker network or a VPC, choose a rarely used private range: 10.0.0.0/8 (16M addresses) is the widest of the 3 private ranges in RFC 1918 §3. Avoid 192.168.1.0/24 and 172.17.0.0/16 because they often overlap with the office/Docker defaults.
-
VLSM
- Value: Variable Length Subnet Masking
- Why: Splitting subnets unevenly according to need. E.g. a 100-person department needs /25 (126 IPs), a 20-person department only needs /27 (30 IPs). It saves IPs instead of splitting evenly and wasting some.
- When it breaks: Not using VLSM → allocating IPs uniformly → wasted IPs in low-demand subnets, too few IPs in high-demand subnets. When the cloud charges per IP allocation, unnecessary IPs are real money.
- In real deployments: A real AWS example: a public subnet /24 (web servers, many) + a private subnet /24 (app servers) + a DB subnet /27 (only 3-5 RDS instances). VLSM lets each tier have exactly the number of IPs it needs.
Step 1 — Determine how many bits to add
/24 has 8 host bits. To get 4 subnets → you need to move 2 bits from the host part to the network part (2^2 = 4). Result: /26.
When it breaks: Miscounting the bits → picking the wrong CIDR → either too few subnets (not enough to split departments/tiers) or subnets that are too small (not enough IPs for hosts). In a cloud deployment, a subnetting mistake at this step means tearing down the whole VPC.
# Rule: need N subnets → take ceil(log2(N)) bits from the host part
# 4 subnets → 2 bits → /24 + 2 = /26
Observe with:
python3 -c "import math; n=4; bits=math.ceil(math.log2(n)); print(f'Need {bits} bits, new CIDR: /24 + {bits} = /{24+bits}')" — verify the calculation.
Step 2 — Calculate the size of each /26 subnet
/26 has 32−26 = 6 host bits → 2^6 = 64 addresses/subnet → 62 usable hosts. Enough for ~60 hosts per department.
When it breaks: Confusing 64 total addresses with 64 usable → planning comes up 2 IPs short → the last subnet lacks an address for 1 host. On AWS, with 5 more reserved IPs subtracted, a /26 has only 57 usable in practice.
# Block size = 256 / number of subnets = 256 / 4 = 64
# Or: 2^(32 - CIDR) = 2^6 = 64
Observe with:
python3 -c "import ipaddress; n=ipaddress.ip_network('192.168.10.0/26'); print('Total:', n.num_addresses, '| Usable:', n.num_addresses-2, '| First:', next(n.hosts()), '| Last:', list(n.hosts())[-1])" — see the full subnet information.
Step 3 — List the 4 subnets
Networks start at multiples of 64 (the block size): 0, 64, 128, 192. This rule lets you work it out in your head, no pen and paper needed.
When it breaks: Not grasping the rule "boundary = a multiple of the block size" → miscalculating the network/broadcast of each subnet → assigning conflicting IPs or running short of IPs. This error is only discovered when two machines cannot ping each other.
Subnet 1: 192.168.10.0/26 (hosts .1 → .62, broadcast .63)
Subnet 2: 192.168.10.64/26 (hosts .65 → .126, broadcast .127)
Subnet 3: 192.168.10.128/26 (hosts .129 → .190, broadcast .191)
Subnet 4: 192.168.10.192/26 (hosts .193 → .254, broadcast .255)
Observe with:
python3 -c "import ipaddress; [print(str(s)) for s in ipaddress.ip_network('192.168.10.0/24').subnets(new_prefix=26)]" — prints the 4 /26 subnets from the /24.
Symptoms when it breaks:
- 2 hosts in the same subnet cannot ping each other even though they are on the same physical LAN: ip neigh show shows the same IP appearing with 2 different MACs (ARP conflict): 192.168.10.65 dev eth0 lladdr aa:bb:cc:dd:ee:ff and 192.168.10.65 dev eth0 lladdr 11:22:33:44:55:66 — duplicate IP
How to fix:
-
Detect the IP conflict with arping — see whether 2 MACs reply
sudo arping -D -I eth0 192.168.10.65 -
Look at the ARP table to find the duplicate
ip neigh show | sort -
Change the conflicting IP to an unused IP in the subnet
sudo ip addr del 192.168.10.65/26 dev eth0 && sudo ip addr add 192.168.10.70/26 dev eth0
Step 4 — Verify in binary
The 2 bits at positions 25-26 are the "subnet ID". 00/01/10/11 are exactly the 4 subnets. When you hesitate between /27 and /28, looking at these bits tells you right away.
When it breaks: Skipping the binary check → when you meet an unfamiliar CIDR (/19, /21) you cannot work out the subnet boundary → you depend entirely on tools → when no tool is available (a VPS during an incident) you are blind.
bit 25-26↓
S1: 192.168.10. 00 000000 = .0
S2: 192.168.10. 01 000000 = .64
S3: 192.168.10. 10 000000 = .128
S4: 192.168.10. 11 000000 = .192
Observe with:
python3 -c "ip='192.168.10.64'; print(' '.join([format(int(o),'08b') for o in ip.split('.')]))" — see the binary representation of any IP.
Step 5 — Subnet mask for /26
26 one-bits + 6 zero-bits = 11111111.11111111.11111111.11000000 = 255.255.255.192. The number 192 comes from 128+64 = the first 2 bits of the last octet.
When it breaks: Entering the wrong subnet mask when configuring a static IP on a server → the host sends traffic to the wrong gateway → connectivity is lost immediately. This is the #1 error when admins configure servers manually without DHCP.
255.255.255.192
# Rule to remember: the last octet of the mask for CIDRs that fall in the last octet:
# /25=128, /26=192, /27=224, /28=240, /29=248, /30=252
Observe with:
python3 -c "import ipaddress; n=ipaddress.ip_network('192.168.10.0/26'); print('Mask:', n.netmask, '| Wildcard:', n.hostmask)" — confirm the subnet mask and wildcard.
Step 6 — Assign subnets to departments + gateway
Convention: the gateway is usually the .1 of the subnet. Fix it so devs/admins can remember it. The DHCP pool starts at .2.
When it breaks: Assigning a gateway IP outside the subnet → the host cannot ping the gateway → cannot reach the internet even though the switch/cable are fine. Example: subnet 192.168.10.64/26 with gateway 192.168.10.1 = the gateway is in a different subnet.
Sales : 192.168.10.0/26 GW 192.168.10.1
Eng : 192.168.10.64/26 GW 192.168.10.65
HR : 192.168.10.128/26 GW 192.168.10.129
Guest : 192.168.10.192/26 GW 192.168.10.193
Observe with:
ip route show — after configuring, check whether the default route goes via the correct gateway address. ping <gateway_ip> — if the gateway answers ping, routing within the subnet is OK.
Step 7 — Verify with a tool
After calculating by hand you must cross-check. One wrong bit = the whole subnet is broken.
When it breaks: Not verifying → deploying with a wrong subnet → a production incident. A verification tool gives results instantly; there is no reason to skip it. Always cross-check in at least 2 ways (manual + tool).
# Install once: sudo apt install ipcalc
ipcalc 192.168.10.100/26
# Key lines in the output (binary column omitted):
# Network: 192.168.10.64/26
# HostMin: 192.168.10.65
# HostMax: 192.168.10.126
# Broadcast: 192.168.10.127
# Hosts/Net: 62
# Correct: .100 belongs to subnet 2 (64-127)
Observe with:
ipcalc 192.168.10.100/26 — if it is installed (apt install ipcalc). Or: python3 -c "import ipaddress; h=ipaddress.ip_interface('192.168.10.100/26'); print('Network:', h.network, '| Host OK:', h.ip in h.network)"
Scripting: Use this when you need to quickly verify a subnet on a server without ipcalc. Run it ad hoc or embed it in a deploy script to validate the CIDR input before ip addr add.
#!/bin/bash
# subnet-info.sh — Print subnet information from CIDR notation
# Usage: ./subnet-info.sh 192.168.10.100/26
# No need to install ipcalc, only python3 (preinstalled on Ubuntu/Debian)
CIDR=${1:?"Usage: $0 <ip/prefix> — e.g. 192.168.10.100/26"}
python3 - <<EOF
import ipaddress, sys
try:
iface = ipaddress.ip_interface('$CIDR')
net = iface.network
hosts = list(net.hosts())
print(f'Input : $CIDR')
print(f'Network : {net.network_address}/{net.prefixlen}')
print(f'Broadcast: {net.broadcast_address}')
print(f'Mask : {net.netmask}')
print(f'Usable : {len(hosts)} ({hosts[0]} — {hosts[-1]})')
except Exception as e:
print(f'Error: {e}'); sys.exit(1)
EOF
Common misconceptions
- Wrong: Class C is synonymous with /24 — always Right: Class C is an address range (first octet 192–223) per RFC 791 §3.2; prefix length is a separate CIDR concept per RFC 4632. A Class C block (192.168.1.0) can be split into /25, /26, /27 using VLSM.
Confusing classful addressing with CIDR leaves you unable to design arbitrary subnets — you keep thinking a subnet must be /8, /16, /24 along classful boundaries, ignoring the possibility of /22, /26, /28 for specific use cases.
- Wrong: Private IPs cannot collide between companies because they were allocated separately Right: RFC 1918 §3 specifies that private ranges are not routable on the internet and not globally unique — any organization uses the same ranges independently. IP overlap is a real problem when connecting 2 companies over a site-to-site VPN.
Designing a site-to-site VPN without checking for IP overlap first → the tunnel comes up but routing is ambiguous → traffic goes to the wrong destination. You must use different CIDR notation for each site or use NAT-over-VPN to resolve the conflict.
- Wrong: The number of usable hosts in a subnet = 2^(32-n) Right: Usable = 2^(32-n) − 2 because you must subtract the network address (host bits all-0) and the broadcast address (host bits all-1). On an AWS VPC, each subnet reserves 5 more addresses (network, router, DNS, future, broadcast) → actual usable = 2^(32-n) − 5 per the AWS VPC subnet sizing docs.
Choose /28 for a production subnet (16 − 5 = 11 usable on AWS), then add more services → you run out of IPs → re-subnetting is very laborious. Calculate enough up front before creating the VPC, because AWS does not let you change the CIDR of a subnet that has already been created.
- Wrong: The NAT gateway sees the real private IP of each machine in the LAN Right: RFC 3022 defines NAT as replacing the source IP from private → public — external servers see only the NAT gateway's public IP and do not know which private IP is the origin. Only the NAT gateway has the port-mapping table needed to look it up in reverse.
Logging and compliance auditing: the server log records the NAT gateway's IP, not the real machine's IP. You need to enable VPC Flow Logs (AWS) or an equivalent to trace a private IP back when investigating a security incident.
- Wrong: 127.x.x.x is a normal usable Class A range Right: 127.0.0.0/8 is the loopback range per RFC 5735 §3 — reserved, not allocated to ordinary hosts or networks. Usable Class A starts at 1.0.0.0; 0.0.0.0/8 is also reserved (RFC 1122 §3.2.1.3) and cannot be used.
Configuring a server to bind to 127.x.x.x (not 127.0.0.1) thinking it is a LAN IP → the service is only accessible from loopback, and no host in the LAN can connect — a hard error to spot if you do not know the loopback range.
Try it at home
1. Check the current IP + subnet mask on a Linux machine — identify the subnet in use
ip -br addr show
Observation: Look for the interface line with state UP and an IP/CIDR address. Format: 'eth0 UP 192.168.1.10/24'. The /24 is the CIDR of the current subnet. If it is /24, the subnet range is .0-.255 and the gateway is usually .1.
2. Look at the routing table — see which subnet goes through which gateway
ip route
Observation: Look for the line 'default via X.X.X.X' = the default gateway. The other lines are 'connected routes' — the subnets the machine is directly attached to. A subnet in the routing table = the machine can send packets to it directly without a router.
3. Test whether 2 IPs are in the same subnet using the ipcalc tool (needs installing: apt install ipcalc)
ipcalc 192.168.1.100/26
ipcalc 192.168.1.200/26
# Compare the Network of the 2 lines — different = different subnets
Observation: Compare the 'Network:' line of the 2 commands. 192.168.1.100/26 → Network 192.168.1.64. 192.168.1.200/26 → Network 192.168.1.192. Different = the 2 machines are in different subnets → they must go through a router.
4. Create a custom Docker network with its own CIDR — avoid clashing with the VPN/office
docker network create --subnet 10.99.0.0/24 mylab
docker network inspect mylab | grep Subnet
Observation: docker network inspect mylab | python3 -m json.tool — see the full config. IPAM.Config will contain the Subnet and Gateway. Run a container in this network and ping the gateway to confirm the subnet works.
5. Verify broadcast: ping the broadcast address → see many hosts reply (if the OS allows it)
# /24 broadcast
ping -b 192.168.1.255
Observation: If several machines in the subnet reply, you see multiple 'icmp_seq' lines from different IPs. Many modern OSes ignore broadcast ping by default. Use sudo tcpdump -i any 'icmp' to see the broadcast ICMP going out and back.
6. See the binary bits of an IP with Python — understand how the mask AND works
python3 -c "import ipaddress; n=ipaddress.ip_network('192.168.10.100/26', strict=False); print(n.network_address, n.broadcast_address, n.num_addresses)"
Observation: Output: network_address broadcast_address total_addresses. Try changing /26 to /27 and /25 — see how the network/broadcast change. strict=False allows any IP inside the subnet, not only the network address.
Review questions
Question 1. Which subnet does 192.168.1.130/25 belong to?
- 192.168.1.0/25
- 192.168.1.128/25
- 192.168.1.64/25
- 192.168.1.192/25
Answer: 192.168.1.128/25. /25 → block size 128. Subnets start at 0 and 128. .130 > 128 ⇒ subnet 192.168.1.128/25 (covering .128 → .255).
-
192.168.1.0/25: Subnet 192.168.1.0/25 only contains .0 → .127, not .130.
-
192.168.1.64/25: The /25 block size is 128, not 64. It is /26 that has a block of 64.
-
192.168.1.192/25: 192.168.1.192 is not a /25 boundary (multiples of 128: only 0 and 128).
Question 2. How many usable hosts does a /27 have?
- 32
- 30
- 14
- 62
Answer: 30. 32 − 27 = 5 host bits → 2^5 = 32 addresses. Subtract network + broadcast = 30 usable.
-
32: 32 is the total addresses, before subtracting network + broadcast.
-
14: 14 is the usable count of /28 (16 − 2).
-
62: 62 is the usable count of /26 (64 − 2).
Question 3. Which subnet mask is equivalent to /29?
- 255.255.255.224
- 255.255.255.248
- 255.255.255.240
- 255.255.255.252
Answer: 255.255.255.248. /29 = 29 one-bits = 11111111.11111111.11111111.11111000. The last octet 11111000 = 128+64+32+16+8 = 248.
-
255.255.255.224: 224 is /27 (11100000).
-
255.255.255.240: 240 is /28 (11110000).
-
255.255.255.252: 252 is /30 (11111100).
Question 4. Are the two machines 10.0.0.5/28 and 10.0.0.17/28 in the same subnet?
- Yes
- No
Answer: No. The /28 block size = 16. .5 belongs to 10.0.0.0/28 (0-15), while .17 belongs to 10.0.0.16/28 (16-31). Different subnets → they must go through a router.
- Yes: With /24 they would be in the same subnet. But with /28 the block of 16 puts these 2 IPs into 2 different subnets. Remember: subnet boundaries are multiples of the block size.
Question 5. Why can a /31, which has only 2 addresses, still be used?
- Because a /31 does not need network/broadcast addresses, only 2 endpoints for a point-to-point link
- /31 cannot be used in practice
- Because /31 allows more than 2 hosts
- Because the router creates extra addresses itself
Answer: Because a /31 does not need network/broadcast addresses, only 2 endpoints for a point-to-point link. RFC 3021 defines /31 for point-to-point links (router-to-router). With no need for network/broadcast → 2 addresses are enough for the 2 ends of the link. It saves public IPs.
-
/31 cannot be used in practice: It can be used and is very common in ISP/MPLS networks.
-
Because /31 allows more than 2 hosts: /31 has only 1 trailing host bit → exactly 2 IPs, no more.
-
Because the router creates extra addresses itself: A router does not "create" addresses — this is a convention.
Question 6. Is the IP 172.20.0.1 private?
- Yes
- No — because it is not in 192.168/16
- No — because 172.20 differs from 172.16
- Cannot be determined
Answer: Yes. The RFC 1918 private range for 172 is 172.16.0.0/12 = 172.16.0.0 → 172.31.255.255. 172.20 falls within it.
-
No — because it is not in 192.168/16: There are 3 private ranges: 10/8, 172.16/12, 192.168/16. Not just 192.168.
-
No — because 172.20 differs from 172.16: The 172 private range is the whole /12 block from 172.16 to 172.31, not just 172.16.
-
Cannot be determined: It can be determined — check membership in the /12 range.
Question 7. You need a subnet that holds at least 100 hosts. What is the smallest suitable CIDR?
- /24
- /25
- /26
- /23
Answer: /25. /25 = 126 usable (128 − 2), enough for 100. /26 has only 62 < 100. /24 is excessive.
-
/24: /24 has 254 usable → more than needed, wastes IPs (the question asks for the 'smallest suitable').
-
/26: /26 has only 62 usable → not enough for 100.
-
/23: /23 has 510 usable → far too many.
Question 8. In the default Docker bridge 172.17.0.0/16, what is the maximum number of container IPs?
- 255
- 65534
- 254
- 65536
Answer: 65534. /16 = 2^16 = 65536 addresses, minus network + broadcast = 65534 usable. (In practice Docker also keeps .1 for the bridge gateway.)
-
255: 255 is the usable count of /24, not of /16.
-
254: 254 is the usable count of /24 (256 − 2).
-
65536: 65536 is the total addresses, before subtracting network/broadcast.
Flashcards
-
What does CIDR /n mean? The first n bits of the IP are the network, the following 32−n bits are the host. CIDR replaced the rigid old class A/B/C — allowing flexible network division anywhere. This is how modern internet routing works.
-
What is the formula for the number of usable hosts? 2^(32−n) − 2. Subtract 2 because the network address (host bits all 0) + the broadcast address (host bits all 1) cannot be assigned to real hosts. Remembering the formula helps you calculate quickly in your head when planning IPs. /24 → 254, /26 → 62, /28 → 14, /30 → 2.
-
What is the subnet mask of /26? 255.255.255.192 — because the last octet 11000000 = 192. A trick for remembering the last octet of the mask: /25=128, /26=192, /27=224, /28=240, /29=248, /30=252. Each additional CIDR bit adds 64, 32, 16, 8, 4 in turn.
-
What is block size? The size of 1 subnet = 2^(32−n). A subnet boundary is always a multiple of the block size. Block size helps you find the network address fast: /26 block = 64, .100 ∈ subnet .64 (the nearest multiple ≤ 100).
-
What are the network and broadcast addresses? Network = host bits all 0 (identifies the subnet). Broadcast = host bits all 1 (sends to every host in the subnet). Assigning these IPs to a host = conflict. Broadcast is used for ARP/DHCP — it is how hosts find each other when they do not yet know the MAC.
-
What is a wildcard mask? When is it used? The bit-inverse of the subnet mask. 255.255.255.0 ↔ 0.0.0.255. Used in Cisco ACLs and OSPF. Cisco devices are designed to match 'which bits are allowed to differ' → this fits a wildcard better than a subnet mask.
-
What is VLSM and why is it needed? Variable Length Subnet Masking — splitting 1 block into several subnets of different sizes (e.g. /24 → 1 ×/25 + 2 ×/26). Departments have different needs: sales 100 hosts (/25), IT 50 hosts (/26), guest 20 hosts (/27). Splitting evenly wastes IPs.
-
What are the 3 private IP ranges per RFC 1918? 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16. Private = not routed on the internet, needs NAT to get out. Kubernetes/Docker/AWS VPC commonly use these ranges.
-
Why can /31 be used despite having only 2 IPs? RFC 3021 — for point-to-point links between 2 routers. No network/broadcast needed. It saves public IPs for ISPs. A router-to-router link used to need a /30 (4 IPs, 2 usable); now it is just a /31 (2 IPs, both usable).
-
A quick mental trick: which subnet is 192.168.5.130 in with /26? /26 block size is 64. 130 ÷ 64 = 2 remainder 2 → network = 128 (2×64). Subnet: 192.168.5.128/26. No paper needed: every CIDR has its own block size; dividing and taking the integer part times the block size gives the boundary.
-
Subnet mask vs Wildcard mask? Mask: a string of 1 bits (network) + 0 bits (host). Wildcard: the opposite. /24 = mask 255.255.255.0 / wildcard 0.0.0.255. Both describe the network/host boundary — they differ only in representation. Linux/Juniper use masks; Cisco ACLs/OSPF use wildcards.
-
Why are 2 machines with the same IP prefix but different CIDR not necessarily in the same subnet? Because CIDR determines the boundary. 10.0.0.5 and 10.0.0.17 share a subnet under /24, but not under /28 (a block of 16 cuts between .15 and .16). When the CIDR is configured wrong on 2 machines, they 'think' they are in different subnets → they send via the gateway instead of ARPing directly → they cannot reach each other even on the same physical LAN.
-
Number of addresses in /16 vs /24? /16 = 65536 (usable 65534). /24 = 256 (usable 254). Each time the CIDR drops by 1 → the address count doubles. /25 is twice /26. Use this to estimate quickly when planning a VPC/cloud subnet.
-
Which IP in the subnet is usually the default gateway? Convention: the first, .1 (e.g. 192.168.1.1). But it is a convention, not a requirement — it could be .254. Easy for devs/admins to remember. Many routers/firewalls default to .1. When troubleshooting 'cannot reach the internet', always check the gateway first.