Computer Networking Cheatsheet
Subnetting and CIDR
Use this Computer Networking reference while you build software engineering projects, review code, or refresh the syntax you reach for most.
Full CIDR table
The prefix length is how many leading bits are network. Everything else follows from it. Usable hosts are total minus 2 for the network and broadcast addresses.
| CIDR | Subnet mask | Wildcard | Total addresses | Usable hosts | /24s |
|---|---|---|---|---|---|
| /8 | 255.0.0.0 | 0.255.255.255 | 16,777,216 | 16,777,214 | 65,536 |
| /9 | 255.128.0.0 | 0.127.255.255 | 8,388,608 | 8,388,606 | 32,768 |
| /10 | 255.192.0.0 | 0.63.255.255 | 4,194,304 | 4,194,302 | 16,384 |
| /11 | 255.224.0.0 | 0.31.255.255 | 2,097,152 | 2,097,150 | 8,192 |
| /12 | 255.240.0.0 | 0.15.255.255 | 1,048,576 | 1,048,574 | 4,096 |
| /13 | 255.248.0.0 | 0.7.255.255 | 524,288 | 524,286 | 2,048 |
| /14 | 255.252.0.0 | 0.3.255.255 | 262,144 | 262,142 | 1,024 |
| /15 | 255.254.0.0 | 0.1.255.255 | 131,072 | 131,070 | 512 |
| /16 | 255.255.0.0 | 0.0.255.255 | 65,536 | 65,534 | 256 |
| /17 | 255.255.128.0 | 0.0.127.255 | 32,768 | 32,766 | 128 |
| /18 | 255.255.192.0 | 0.0.63.255 | 16,384 | 16,382 | 64 |
| /19 | 255.255.224.0 | 0.0.31.255 | 8,192 | 8,190 | 32 |
| /20 | 255.255.240.0 | 0.0.15.255 | 4,096 | 4,094 | 16 |
| /21 | 255.255.248.0 | 0.0.7.255 | 2,048 | 2,046 | 8 |
| /22 | 255.255.252.0 | 0.0.3.255 | 1,024 | 1,022 | 4 |
| /23 | 255.255.254.0 | 0.0.1.255 | 512 | 510 | 2 |
| /24 | 255.255.255.0 | 0.0.0.255 | 256 | 254 | 1 |
| /25 | 255.255.255.128 | 0.0.0.127 | 128 | 126 | ½ |
| /26 | 255.255.255.192 | 0.0.0.63 | 64 | 62 | ¼ |
| /27 | 255.255.255.224 | 0.0.0.31 | 32 | 30 | — |
| /28 | 255.255.255.240 | 0.0.0.15 | 16 | 14 | — |
| /29 | 255.255.255.248 | 0.0.0.7 | 8 | 6 | — |
| /30 | 255.255.255.252 | 0.0.0.3 | 4 | 2 | — |
| /31 | 255.255.255.254 | 0.0.0.1 | 2 | 2 (RFC 3021) | — |
| /32 | 255.255.255.255 | 0.0.0.0 | 1 | 1 (host route) | — |
Total addresses = 2^(32 − prefix). Usable = that minus 2, except /31 point-to-point links (both addresses usable) and /32 single-host routes.
The two numbers to memorize
Everything in subnetting comes from the mask octet values and the block size.
| Host bits in the octet | 8 | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
|---|---|---|---|---|---|---|---|---|---|
| Mask octet | 0 | 128 | 192 | 224 | 240 | 248 | 252 | 254 | 255 |
| Block size | 256 | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
Block size = 256 − mask octet. Subnets start at multiples of the block size, so a /26 (block 64) always starts at .0, .64, .128, .192.
Worked example: split 192.168.1.0/24 into /26 subnets
- Prefix goes 24 → 26, so you borrow 2 host bits, giving 2² = 4 subnets.
- Mask becomes
255.255.255.192. Interesting octet is the fourth. - Block size = 256 − 192 = 64.
- Networks step by 64. Broadcast is the next network minus 1.
| Subnet | Network | First host | Last host | Broadcast |
|---|---|---|---|---|
| 1 | 192.168.1.0/26 | .1 | .62 | .63 |
| 2 | 192.168.1.64/26 | .65 | .126 | .127 |
| 3 | 192.168.1.128/26 | .129 | .190 | .191 |
| 4 | 192.168.1.192/26 | .193 | .254 | .255 |
Worked example: which subnet holds 10.20.130.77/19?
1. /19 = 16 network bits + 3 borrowed, interesting octet is the third.
2. Mask = 255.255.224.0, block size = 256 − 224 = 32.
3. Third octet 130 ÷ 32 = 4 remainder 2, so it falls in the block starting at
4 × 32 = 128.
network 10.20.128.0/19 first host 10.20.128.1 last host 10.20.159.254 broadcast 10.20.159.255 next net 10.20.160.0 usable 8190 hosts
The bitwise way, always correct: AND the address with the mask for the network, OR it with the wildcard for the broadcast.
VLSM, sizing subnets to the hosts they hold
Variable Length Subnet Masking allocates different prefix lengths out of one block instead of splitting it evenly. Always allocate largest first, or you fragment the space and cannot fit the big subnets later.
Given 172.16.0.0/22 (1024 addresses) and these needs:
| Need | Hosts required | Prefix chosen | Capacity | Allocation |
|---|---|---|---|---|
| Office LAN | 400 | /23 | 510 | 172.16.0.0/23 |
| Wi-Fi | 200 | /24 | 254 | 172.16.2.0/24 |
| Servers | 50 | /26 | 62 | 172.16.3.0/26 |
| Management | 20 | /27 | 30 | 172.16.3.64/27 |
| WAN link A | 2 | /30 | 2 | 172.16.3.96/30 |
| WAN link B | 2 | /30 | 2 | 172.16.3.100/30 |
| Free | — | — | 152 | 172.16.3.104-.255 |
Pick the prefix where usable hosts ≥ requirement: 400 needs 512 total, so /23. Leave gaps on purpose, renumbering later is far more painful.
Supernetting and route summarization
The reverse operation. Contiguous blocks that share leading bits collapse into one shorter prefix, which shrinks routing tables.
192.168.4.0/24 → 11000000.10101000.00000100.00000000 192.168.5.0/24 → 11000000.10101000.00000101.00000000 192.168.6.0/24 → 11000000.10101000.00000110.00000000 192.168.7.0/24 → 11000000.10101000.00000111.00000000 ^^^^^^^^^^^^^^^^^^^^^^ 22 bits identical summary: 192.168.4.0/22
Blocks must be contiguous and the summary must start on a boundary that is a
multiple of its own size. 192.168.5.0/22 is invalid, because 5 is not a
multiple of 4.
Command-line subnet math
ipcalc 192.168.1.0/26 # network, broadcast, host range ipcalc -b 10.20.130.77/19 sipcalc 172.16.0.0/22 # deb: sipcalc, includes splitting python3 -c 'import ipaddress as i; \ n=i.ip_network("192.168.1.0/24"); \ print([str(s) for s in n.subnets(new_prefix=26)])' python3 -c 'import ipaddress as i; \ print(i.ip_address("10.20.130.77") in i.ip_network("10.20.128.0/19"))' nmap -sn 192.168.1.0/24 # who answers in the range