The IP address of any computer belongs to a subnet: a range of IP addresses that can talk to each other over a Layer 2 (switching) network.

The size of this range can be written in several ways. For example, “255.255.255.0” and “/24” are two equivalent ways to write the same thing.

To understand what these numbers mean, though, first you’ll need to know binary. Good?

Comparing an IP address and subnet mask

Now, let’s look at an example IP address and subnet mask, each broken out by octet and then written in binary:

Written asOctet 1Octet 2Octet 3Octet 4
IP address (decimal)19216801
IP address (binary)11000000101010000000000000000001
Subnet mask (decimal)2552552550
Subnet mask (binary)11111111111111111111111100000000

See how each octet lines up?

This IP address and subnet mask combination means that the subnet for 192.168.0.1 extends from 192.168.0.0 through 192.168.0.255. But why?

Network bits and host bits

The key is in the binary! Look at the subnet mask from above, 255.255.255.0, in binary:

11111111.11111111.11111111.00000000

Note that there are 32 bits in total: 8 for each octet (oct = 8). Reading from left to right, it has 1s until a certain point, and then 0s.

The bits with 1s are network bits, and the bits with 0s are host bits:

PartValueNumber of bits
Network bits11111111.11111111.1111111124
Host bits000000008

255.255.255.0 = /24

Every address in a subnet has the same network bits. With this subnet mask, the only thing that can vary is the last 8 bits, from 00000000 (0) to 11111111 (255).

Network and broadcast addresses

Two addresses in most subnets have special jobs, so they can’t be given to a computer:

  • Network address: all of the host bits are 0. This is the first address, and it identifies the subnet itself.
  • Broadcast address: all of the host bits are 1. This is the last address, and it reaches every device in the subnet.

Everything in between can be assigned to devices. To count the usable addresses, raise 2 to the number of host bits, then subtract these two special addresses. A /24 has 8 host bits:

2⁸ − 2 = 256 − 2 = 254 usable addresses

There are two exceptions. A /31 has only two addresses, and both can be used on a link between two devices. A /32 is a single address.

When the mask splits an octet

A /24 is easy to read because the network bits end exactly where the third octet ends. That isn’t always true. Let’s find the subnet for 192.168.1.130/26.

A /26 has 26 network bits, which leaves 32 − 26 = 6 host bits. The first three octets use 24 network bits, so the last octet has 2 network bits (in bold) and 6 host bits:

AddressLast octet (binary)Last octet (decimal)
IP address10000010130
Subnet mask11000000192
Network address (host bits all 0)10000000128
Broadcast address (host bits all 1)10111111191

The network bits stay the same, and only the host bits change. So:

  • Subnet mask: 255.255.255.192
  • Network address: 192.168.1.128
  • Broadcast address: 192.168.1.191
  • Usable addresses: 192.168.1.129 through 192.168.1.190
  • Number of usable addresses: 2⁶ − 2 = 62

A shortcut: block size

Once the binary makes sense, there’s a faster way. Find the octet where the mask isn’t 255 or 0, and subtract the mask’s value in that octet from 256. The answer is the block size. Subnets start at multiples of the block size.

For a /26, the mask is 255.255.255.192, so the block size is 256 − 192 = 64. In the last octet, subnets start at 0, 64, 128 and 192. Since 130 falls between 128 and 191, its network address ends in 128. That’s the same answer we found in binary.

Here are some common subnet sizes. For all of these, the block size applies to the last octet:

PrefixSubnet maskHost bitsBlock sizeUsable addresses
/25255.255.255.1287128126
/26255.255.255.19266462
/27255.255.255.22453230
/28255.255.255.24041614
/29255.255.255.248386
/30255.255.255.252242

Practice

For each address, find the subnet mask, network address, broadcast address and number of usable addresses. Try these before looking at the answers below:

  1. 10.0.5.77/27
  2. 172.16.20.200/28
  3. 192.168.10.5/22 (Hint: look at the third octet.)

Answers

AddressSubnet maskNetwork addressBroadcast addressUsable addresses
10.0.5.77/27255.255.255.22410.0.5.6410.0.5.9530
172.16.20.200/28255.255.255.240172.16.20.192172.16.20.20714
192.168.10.5/22255.255.252.0192.168.8.0192.168.11.2551,022

For the last one, the mask splits the third octet. The block size is 256 − 252 = 4, so subnets start at multiples of 4 in that octet. The multiple of 4 at or just below 10 is 8, so the subnet starts at 192.168.8.0. The next one starts at 192.168.12.0, so this one ends just before it, at 192.168.11.255.

All Knowledge Base articles