LearnNetwork
IPv4 addressing and subnetting

IPv4 addressing and subnetting (the fast way)

15 min

Subnetting drove every networking exam for decades. Now it's mechanical — once you have the technique, every question takes under 15 seconds. This lesson is the technique. Practice the calculator below until it's automatic.

Network address
192.168.1.0/24
Broadcast
192.168.1.255
Subnet mask
255.255.255.0
Wildcard
0.0.0.255
Usable hosts
254
First usable
192.168.1.1
Last usable
192.168.1.254

The address itself

IPv4 is 32 bits, written as four 8-bit numbers (octets) separated by dots: 192.168.1.42. Every octet is 0–255. Behind the scenes:

192       . 168       . 1         . 42
11000000   10101000   00000001   00101010

That's it. Everything else about addressing — classes, masks, subnets — is just rules for how to interpret which bits identify the network and which identify the host.

Mask and prefix length

A mask is a 32-bit number aligned with the address. Every 1 in the mask means "this bit is the network portion"; every 0 means "this bit is the host portion."

IP:    192.168.1.42        11000000.10101000.00000001.00101010
Mask:  255.255.255.0       11111111.11111111.11111111.00000000

The number of 1s in the mask is the prefix length: here, 24. We write the whole thing as CIDR: 192.168.1.42/24.

| Prefix | Mask | Hosts (usable) | |---|---|---| | /24 | 255.255.255.0 | 254 | | /25 | 255.255.255.128 | 126 | | /26 | 255.255.255.192 | 62 | | /27 | 255.255.255.224 | 30 | | /28 | 255.255.255.240 | 14 | | /29 | 255.255.255.248 | 6 | | /30 | 255.255.255.252 | 2 | | /31 | 255.255.255.254 | 2 (point-to-point) |

The "minus 2" is because every subnet reserves the all-zeros host bits for the network address and the all-ones for the broadcast. /31 is the exception for point-to-point links.

The fast technique

For any X.Y.Z.W/N:

  1. Find which octet contains the prefix boundary: divide N by 8. The integer part says how many octets are "all network"; the remainder says how many bits of the next octet are network.
  2. Compute the block size in that octet: block = 256 - mask_octet_value. Equivalently 2^(8 - remainder).
  3. The network address aligns at a multiple of the block size in that octet.
  4. The broadcast is network + block - 1.
  5. Usable hosts: network + 1 to broadcast - 1.

Example: 10.0.0.135/27.

  • 27 / 8 = 3 remainder 3 → the 4th octet has 3 network bits.
  • Mask octet = 11100000 = 224. Block = 256 − 224 = 32.
  • Network: round 135 down to multiple of 32 → 128. So 10.0.0.128.
  • Broadcast: 128 + 32 − 1 = 159. So 10.0.0.159.
  • Usable: 10.0.0.12910.0.0.158 (30 hosts).

That's the whole game. Practice with the SubnetCalculator widget above — type random CIDRs and verify your mental answer.

Private vs public address space

| Range | CIDR | Use | |---|---|---| | 10.0.0.0 – 10.255.255.255 | 10.0.0.0/8 | Private (RFC 1918) — enterprises, big LANs | | 172.16.0.0 – 172.31.255.255 | 172.16.0.0/12 | Private | | 192.168.0.0 – 192.168.255.255 | 192.168.0.0/16 | Private — home routers | | 169.254.0.0/16 | | Link-local / APIPA (when DHCP fails) | | 127.0.0.0/8 | | Loopback (mostly 127.0.0.1) | | 224.0.0.0/4 | | Multicast | | 0.0.0.0/8, 240.0.0.0/4 | | Reserved / experimental | | Everything else | | Public — assigned by IANA / RIRs |

Private ranges need NAT to reach the internet — covered in Track D.

Special-purpose addresses

| Address | Meaning | |---|---| | 0.0.0.0 | "this host, this network" (DHCP-discovering host before it has an IP) | | 0.0.0.0/0 | Default route — "any destination" | | 255.255.255.255 | Limited broadcast (does not cross routers) | | <network>.<all-zeros host> | Network address — never assign to a host | | <network>.<all-ones host> | Directed broadcast |

What to remember

  • Address is 32 bits + mask. Prefix length = number of mask 1-bits.
  • Number of hosts = 2^(32-prefix) − 2, except /31 (= 2).
  • The fast subnetting technique: find the octet, compute block = 256 − mask, round down for network, broadcast = network + block − 1.
  • Memorise the private ranges (10/8, 172.16/12, 192.168/16).