All posts

Network Fundamentals: IPv4 Addressing and Subnetting

Masks, prefixes, block sizes and worked examples — subnetting by hand until each problem takes under thirty seconds.

Marijan Kopčić••2 min read
Network Fundamentals: IPv4 Addressing and Subnetting

Subnetting is the one networking skill you can't talk your way around — either you get the network and broadcast address right, or you don't. The good news is that it is a method, not a talent. Learn the table and the block size trick, then practise until each problem takes under thirty seconds.

What the mask and the default gateway do

The mask says which part of an address is the network and which part is the host. With it, a computer can tell whether a destination is in its own subnet. If it is, the packet goes straight there. If it isn't, the packet goes to the default gateway — the router.

Binary in your head

An octet has eight bits worth 128 64 32 16 8 4 2 1. Mask octets are always ones from the left, so there are only a handful to remember:

Binary Decimal
10000000 128
11000000 192
11100000 224
11110000 240
11111000 248
11111100 252
11111110 254
11111111 255

The prefix table

Prefix Mask Addresses Usable hosts
/16 255.255.0.0 65,536 65,534
/21 255.255.248.0 2,048 2,046
/22 255.255.252.0 1,024 1,022
/23 255.255.254.0 512 510
/24 255.255.255.0 256 254
/25 255.255.255.128 128 126
/26 255.255.255.192 64 62
/27 255.255.255.224 32 30
/28 255.255.255.240 16 14
/29 255.255.255.248 8 6
/30 255.255.255.252 4 2

Usable hosts are always 2^(32 − prefix) − 2: the first address is the network, the last is the broadcast.

The block size method

  1. Find the "interesting" octet — the one in the mask that is neither 255 nor 0.
  2. Block size is 256 − that octet. For /26 the octet is 192, so the block is 64.
  3. Subnets start at multiples of the block: 0, 64, 128, 192.
  4. The network is the multiple at or below your address. The broadcast is the next multiple minus one. Hosts are everything in between.

Worked examples

192.168.10.77/26

Block 64. 77 falls between 64 and 128.

  • Network: 192.168.10.64
  • Broadcast: 192.168.10.127
  • Hosts: .65 to .126, 62 in total
  • Mask: 255.255.255.192

172.16.5.130/27

Block 32. 130 falls between 128 and 160.

  • Network: 172.16.5.128
  • Broadcast: 172.16.5.159
  • Hosts: .129 to .158, 30 in total

10.20.30.200/21

The mask is 255.255.248.0, so the interesting octet is the third one and the block is 8. 30 falls between 24 and 32.

  • Network: 10.20.24.0
  • Broadcast: 10.20.31.255
  • Hosts: 2,046

Are 192.168.1.120/25 and 192.168.1.130/25 in the same subnet?

No. A /25 splits the /24 into .0–.127 and .128–.255. The two hosts are on different sides of that line and need a router to talk to each other.

Sizing a subnet

Pick the smallest prefix whose usable host count covers the need:

  • 50 hosts → /26 (62)
  • 500 hosts → /23 (510)
  • A link between two routers → /30 (2 hosts), or /31, which uses both addresses on a point-to-point link

Private and special ranges

  • Private: 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16
  • Loopback: 127.0.0.0/8
  • APIPA: 169.254.0.0/16 — the computer didn't get an address from DHCP
  • CGNAT: 100.64.0.0/10 — shared address space used by ISPs for carrier-grade NAT

Keep reading