Step 3 — Subnet Masks

The subnet mask is what tells a device which part of an IP address is the network and which part is the host. Master this, and subnetting becomes intuitive.

What is a Subnet Mask?

A subnet mask is a 32-bit number that "masks" the IP address to reveal the network portion. It's written the same way as an IP address:

255.255.255.0

In binary, a subnet mask is a series of 1s followed by 0s. The 1s mark the network bits, the 0s mark the host bits.

The Binary View

Here's 255.255.255.0 in binary:

OctetDecimalBinary
1st25511111111
2nd25511111111
3rd25511111111
4th000000000

24 network bits (1s) + 8 host bits (0s) = 32 total bits

Common Subnet Masks

You need to memorize these. They appear constantly in networking:

DecimalBinaryNetwork Bits
255.0.0.011111111.00000000.00000000.00000000/8
255.255.0.011111111.11111111.00000000.00000000/16
255.255.255.011111111.11111111.11111111.00000000/24
255.255.255.12811111111.11111111.11111111.10000000/25
255.255.255.19211111111.11111111.11111111.11000000/26
255.255.255.22411111111.11111111.11111111.11100000/27
255.255.255.24011111111.11111111.11111111.11110000/28
255.255.255.24811111111.11111111.11111111.11111000/29
255.255.255.25211111111.11111111.11111111.11111100/30

The Magic Numbers

Notice that subnet mask octets only use specific values. These are the only valid numbers in a subnet mask:

0, 128, 192, 224, 240, 248, 252, 254, 255

Each represents a valid boundary for the network/host split

DecimalBinaryNetwork BitsHost Bits
00000000008
1281000000017
1921100000026
2241110000035
2401111000044
2481111100053
2521111110062
2541111111071
2551111111180

How Masking Works (AND Operation)

When a device applies a subnet mask, it performs a bitwise AND operation. Anywhere the mask has a 1, the IP bit is preserved. Anywhere it's 0, the result is 0.

IP Address:192.168.1.100Binary:
11000000.10101000.00000001.01100100
Subnet Mask:255.255.255.0Binary:
11111111.11111111.11111111.00000000
AND Result:192.168.1.0Binary:
11000000.10101000.00000001.00000000

The result (192.168.1.0) is the network address. The host bits become all zeros.

Practice Exercises

  1. What is 255.255.255.192 in binary?
  2. How many network bits does 255.255.240.0 have?
  3. A mask has 25 network bits. What is it in decimal?
  4. Given IP 10.50.100.200 and mask 255.255.255.0, what is the network address?
Show Answers
  1. 11111111.11111111.11111111.11000000
  2. 20 network bits (8 + 8 + 4 = 20, since 240 = 11110000)
  3. 255.255.255.128 (25 bits = 8+8+8+1)
  4. 10.50.100.0 (host bits zeroed out)

Checkpoint

Before moving on, make sure you can:

  • Convert any subnet mask to binary
  • Count network bits from a subnet mask
  • Recognize the "magic numbers" (0, 128, 192, 224, 240, 248, 252, 254, 255)
  • Apply a subnet mask to find the network address