Subnetting and Network Math

The arithmetic behind every network. Fewer tricks than you were told, and one boundary that explains all of it.

The one idea underneath everything

Subnetting has a reputation for being hard, and the reason is that it is usually taught as a set of procedures to memorize. It is really one idea: an address is 32 bits, and a line is drawn through them. Everything to the left of the line identifies the network. Everything to the right identifies a host inside it.

Move the line right and you get more networks with fewer hosts each. Move it left and you get fewer, larger networks. Every question in this subject is asking where the line is or what follows from where it sits.

1. CIDR notation

Full article →

CIDR, Classless Inter-Domain Routing, writes the line's position as a number after a slash. 10.0.0.0/24 means the first 24 bits are network, leaving 8 for hosts.

How a CIDR prefix splits a network in half Each bit added to the prefix halves the block. A slash 24 holds 256 addresses, two slash 25s hold 128 each, and four slash 26s hold 64 each. Every bit you add to the prefix cuts the block in half /24 10.0.0.0/24, 256 addresses /25 10.0.0.0/25, 128 10.0.0.128/25, 128 /26 .0/26, 64 .64/26, 64 .128/26, 64 .192/26, 64 /27 eight blocks of 32 The number after the slash is how many bits identify the NETWORK, so a bigger number is a smaller block. A /30 is four addresses. A /8 is sixteen million.
Each bit added to the prefix halves the block. This is the whole of the arithmetic, and the counterintuitive part is that a bigger number means a smaller network.

CIDR replaced the old class system in 1993, where a network could only be one of three fixed sizes. An organization with 300 machines was too big for a Class C's 254 and got a Class B's 65,534 instead, wasting 65,000 addresses. CIDR lets a block be any power of two, so that same organization takes a /23 and wastes about 200.

2. Subnet masks and binary

Full article →

A subnet mask says the same thing as a CIDR prefix, in the older dotted-decimal form. /24 and 255.255.255.0 are two spellings of one fact.

A subnet mask is a line drawn through 32 bits The mask marks where the network part of an address ends and the host part begins. A slash 26 means the first 26 bits are network and the last 6 are host, which is 255.255.255.192 in dotted decimal. The mask marks one boundary, and everything else follows from where it sits Address 192.168.1.130 11000000 10101000 00000001 10000010 Mask /26 255.255.255.192 11111111 11111111 11111111 11000000 the boundary 26 network bits, identical for every host here 6 host bits What the host bits give you 6 host bits means 2 to the power of 6, which is 64 addresses in the block. Two are reserved: the lowest is the network address and the highest is the broadcast address, so 62 are usable. Worth memorizing: usable hosts equals 2 to the power of (32 minus the prefix), minus 2. The exceptions are /31, which has 2 usable and no broadcast, and /32, which is a single host.
The mask is all ones for the network part and all zeros for the host part. Written in binary it is literally a line, which is why the binary view makes the whole subject click.

Because a mask is always ones followed by zeros, only nine values can appear in any octet, and knowing them by sight removes most of the arithmetic.

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

3. Network, broadcast and usable hosts

Full article →

Every block reserves two addresses. The lowest is the network address, naming the block itself. The highest is the broadcast address, reaching every host at once. Neither can be assigned to a device, which is where the "minus two" in every formula comes from.

usable hosts = 2 ^ (32 - prefix) - 2

/24  ->  2^8  - 2 = 254
/26  ->  2^6  - 2 = 62
/30  ->  2^2  - 2 = 2

4. A worked example

Given 192.168.1.130/26, find the network, broadcast, and usable range. This is the exam question, and it takes about fifteen seconds once you see the shape.

  1. Block size. A /26 leaves 6 host bits, so the block holds 26 = 64 addresses.
  2. Where the blocks start. They begin at multiples of 64: .0, .64, .128, .192.
  3. Which one holds .130? It falls between 128 and 191, so the network is 192.168.1.128.
  4. Broadcast. The last address in the block, 192.168.1.191.
  5. Usable. Everything between, .129 through .190. That is 62 addresses.

The trick worth keeping is step 2. Once you know the block size, the boundaries are just multiples of it, and the rest is reading off which interval your address lands in.

The shortcut most people are actually taught

256 minus the interesting octet of the mask gives the block size. For 255.255.255.192, that is 256 minus 192 = 64. It is the same arithmetic as counting host bits, and it is faster under time pressure.

5. Splitting unevenly with VLSM

Real networks are not made of equal pieces. Variable Length Subnet Masking just means using different prefix lengths for different subnets inside one block, rather than cutting everything the same size.

The method is to sort your requirements largest first and allocate in that order, because a large block can only start on a boundary that is a multiple of its own size. Allocating small pieces first strands the space a big one needed.

Splitting 10.0.0.0/24 for 100 users, 50 phones, 20 printers and a 2-address router link:

NeedPrefixBlockUsable
100 users/2510.0.0.0 to 10.0.0.127126
50 phones/2610.0.0.128 to 10.0.0.19162
20 printers/2710.0.0.192 to 10.0.0.22330
Router link/3010.0.0.224 to 10.0.0.2272

Note that 100 users needs a /25 and not a /26, because 62 usable is not enough. Always round up to the next power of two, then subtract two.

6. The special cases

/30, the classic point-to-point link

Four addresses, two usable, one at each end of a link between two routers. Two of four wasted, which used to be simply accepted.

/31, which breaks the rule

RFC 3021 allows a /31 on point-to-point links, where there is no network or broadcast address and both addresses are usable. The formula's "minus two" does not apply. This is the case most calculators get wrong, and it is standard practice on modern router links.

/32, a single host

One address, no block around it. You see these on loopback interfaces, in routing tables for a single destination, and throughout firewall rules.

7. The cheat sheet

Full page →

Every IPv4 prefix, its mask, block size, and usable host count, on one page worth bookmarking.

CIDRMaskAddressesUsable
/24255.255.255.0256254
/25255.255.255.128128126
/26255.255.255.1926462
/27255.255.255.2243230
/28255.255.255.2401614
/29255.255.255.24886
/30255.255.255.25242

The full sheet covers /8 through /32, plus the reserved ranges and the wildcard masks used in access lists. There is a one-page PDF as well, for printing.

Read any section in full