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.

CIDRSubnet maskWildcardTotal addressesUsable hosts/24s
/8255.0.0.00.255.255.25516,777,21616,777,21465,536
/9255.128.0.00.127.255.2558,388,6088,388,60632,768
/10255.192.0.00.63.255.2554,194,3044,194,30216,384
/11255.224.0.00.31.255.2552,097,1522,097,1508,192
/12255.240.0.00.15.255.2551,048,5761,048,5744,096
/13255.248.0.00.7.255.255524,288524,2862,048
/14255.252.0.00.3.255.255262,144262,1421,024
/15255.254.0.00.1.255.255131,072131,070512
/16255.255.0.00.0.255.25565,53665,534256
/17255.255.128.00.0.127.25532,76832,766128
/18255.255.192.00.0.63.25516,38416,38264
/19255.255.224.00.0.31.2558,1928,19032
/20255.255.240.00.0.15.2554,0964,09416
/21255.255.248.00.0.7.2552,0482,0468
/22255.255.252.00.0.3.2551,0241,0224
/23255.255.254.00.0.1.2555125102
/24255.255.255.00.0.0.2552562541
/25255.255.255.1280.0.0.127128126½
/26255.255.255.1920.0.0.636462¼
/27255.255.255.2240.0.0.313230—
/28255.255.255.2400.0.0.151614—
/29255.255.255.2480.0.0.786—
/30255.255.255.2520.0.0.342—
/31255.255.255.2540.0.0.122 (RFC 3021)—
/32255.255.255.2550.0.0.011 (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 octet876543210
Mask octet0128192224240248252254255
Block size2561286432168421

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

  1. Prefix goes 24 → 26, so you borrow 2 host bits, giving 2² = 4 subnets.
  2. Mask becomes 255.255.255.192. Interesting octet is the fourth.
  3. Block size = 256 − 192 = 64.
  4. Networks step by 64. Broadcast is the next network minus 1.
SubnetNetworkFirst hostLast hostBroadcast
1192.168.1.0/26.1.62.63
2192.168.1.64/26.65.126.127
3192.168.1.128/26.129.190.191
4192.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:

NeedHosts requiredPrefix chosenCapacityAllocation
Office LAN400/23510172.16.0.0/23
Wi-Fi200/24254172.16.2.0/24
Servers50/2662172.16.3.0/26
Management20/2730172.16.3.64/27
WAN link A2/302172.16.3.96/30
WAN link B2/302172.16.3.100/30
Free——152172.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