Find a course

Module 2: Addressing: MAC, IPv4, Subnets and IPv6Lesson 5 of 1313 min

Subnet Masks and CIDR

Use subnet masks and CIDR prefixes like /24 to find the network, the usable host range and the broadcast address, and decide if two hosts share a subnet.

Step 1 of 12Learn

Which part is the street?

An IP address has two parts: a network part that identifies which network the device is on, and a host part that identifies the device within that network. Think of a street name and a house number. All devices on one local network share the same network part.

The dividing line is set by the subnet mask. Written in binary, a mask is a run of 1s followed by 0s. The 1s mark the network bits and the 0s mark the host bits:

Address  192.168.1.20   11000000.10101000.00000001.00010100
Mask     255.255.255.0  11111111.11111111.11111111.00000000
Network  192.168.1.0    (first 24 bits kept, host bits zeroed)

Instead of writing the whole mask, CIDR notation (Classless Inter-Domain Routing) appends a slash and the number of network bits: 192.168.1.20/24 means the first 24 bits are the network. So /24 equals 255.255.255.0, /16 equals 255.255.0.0, and /8 equals 255.0.0.0.

Why it matters in practice: your computer uses the mask to decide whether a destination is local (send directly, using ARP) or remote (send to the default gateway, the router). A wrong mask can make a computer think a local printer is far away, or a remote server is next door, and both break communication.

Step 2 of 12Learn

Counting hosts

With n network bits, there are 32 − n host bits. Each host bit doubles the number of addresses:

Addresses in the subnet = 2^(32 − n)

Two of them are reserved in a normal subnet:

  • The network address, where all host bits are 0, names the subnet itself, such as 192.168.1.0.
  • The broadcast address, where all host bits are 1, reaches every device in the subnet, such as 192.168.1.255.

So usable hosts = 2^(32 − n) − 2.

PrefixMaskAddressesUsable hosts
/24255.255.255.0256254
/25255.255.255.128128126
/26255.255.255.1926462
/27255.255.255.2243230
/28255.255.255.2401614
/30255.255.255.25242
/16255.255.0.065,53665,534

Each step of one bit halves the subnet. A /24 can be split into two /25s, four /26s or eight /27s. A larger prefix number means a smaller network, which trips people up at first: a /28 is much smaller than a /24.

The mask octets you see, 128, 192, 224, 240, 248, 252, 254, 255, are just runs of 1-bits from the left: 128 = 10000000, 192 = 11000000, 224 = 11100000, and so on.

Step 3 of 12Try the calculator

Subnet size calculator

Enter a prefix length between 8 and 30. The calculator shows the addresses and usable hosts in one subnet, and how many such subnets fit in a /24.

Host bits
6
Addresses in the subnet
64
Usable host addresses
62
Subnets of this size in one /24 (for n ≥ 24)
4

Step 4 of 12Practice · Work it out

How many usable host addresses does a /27 subnet have?

Step 5 of 12Learn

Finding the network and broadcast address

For prefixes in the last octet (/25 to /30), there's a fast method using the block size: 256 minus the mask's last octet. Subnets start at multiples of the block size.

Example: 192.168.10.77/26.

  1. Mask for /26: 255.255.255.192. Block size = 256 − 192 = 64.
  2. Subnets start at 0, 64, 128, 192. The address 77 falls in the block starting at 64.
  3. Network address: 192.168.10.64.
  4. Broadcast address: one less than the next block, 192.168.10.127.
  5. Usable hosts: 192.168.10.65 to 192.168.10.126, which is 62 hosts, matching the table.

Are two hosts on the same subnet? Work out the network address of each with the same mask. 192.168.10.77/26 and 192.168.10.130/26 look close, but 130 falls in the block starting at 128, so they are on different subnets and need a router to talk.

The default gateway is the router's address on the local subnet, usually the first or last usable address, such as 192.168.10.65. A host whose gateway is outside its own subnet can't reach it, a classic misconfiguration.

Subnetting in real life: a company might split 10.0.0.0/16 into /24s per floor or department, which keeps broadcast traffic contained and lets firewalls apply different rules to each subnet.

Step 6 of 12Practice · Fill in the blanks

Fill in the blanks

For the host 172.16.5.200/28, the block size is , the network address is `172.16.5., and the broadcast address is 172.16.5.`.

Step 7 of 12Diagram

/28 blocks in the last octet of 172.16.5.x

/28 blocks in the last octet of 172.16.5.xScale: Network .192, Host .200, Broadcast .207, Next network .208..176/28.192/28.208/28180190200210220192Network .192200Host .200207Broadcast .207208Next network .208

Tap a shape with to see more.

Block size 16: subnets start at multiples of 16.
Network .192

First address of the block: identifies the subnet.

Host .200

The address from the exercise above.

Broadcast .207

Last address of the block.

Next network .208

A different subnet: needs a router to reach.

Step 8 of 12Practice · Select all that apply

A host is configured as 192.168.4.10/25. Which of these addresses are on the same subnet? Select all that apply.

Select all that apply.

Step 9 of 12Note

Step 10 of 12Practice · Work it out

A company needs a subnet for 100 devices. What is the largest prefix length (the smallest subnet) that still fits them?

Step 11 of 12Practice · Chart

Usable hosts per prefix length

Each extra prefix bit halves the subnet (minus the network and broadcast addresses).

A lab needs 50 devices. Which is the smallest subnet that fits?

Tap the bar that answers the question, then press Check.

Usable hosts per prefix lengthBar chart with 7 categories: /24: 254; /25: 126; /26: 62; /27: 30; /28: 14; /29: 6; /30: 2.0100200300Usable host addresses/24/25/26/27/28/29/30Prefix length25412662301462
Usable hosts per prefix length
Prefix lengthUsable hosts
/24254
/25126
/2662
/2730
/2814
/296
/302

Step 12 of 12Practice · What would you do?

What would you do?

A new PC is set to IP 10.1.1.50, mask 255.255.255.0, gateway 10.1.2.1. It can reach other PCs on 10.1.1.x but nothing on the internet. What is wrong?