Labs / Networking

CIDR / IPv4 Subnet Lab

Visualize IPv4 subnetting. See the exact boundary between network bits and host bits.

New to this? There\'s a lesson below ↓
← BACK TO LABS
Subnet Calculator
/24
/0 (Internet) /32 (Host)
SUBNET MASK
255.255.255.0
NETWORK ADDRESS
192.168.1.0
BROADCAST ADDRESS
192.168.1.255
USABLE RANGE
192.168.1.1 - 192.168.1.254
TOTAL HOSTS
256
USABLE HOSTS
254
What's happening?

An IPv4 address is 32 bits long. CIDR (Classless Inter-Domain Routing) splits these 32 bits into two parts:

  • Network Bits: Identified by the prefix length (e.g., /24 means the first 24 bits). These define the network itself.
  • Host Bits: The remaining bits (e.g., 32 - 24 = 8). These identify individual devices on that network.

Subnet Mask: A 32-bit number where all network bits are 1 and all host bits are 0.

Network Address: All host bits set to 0. Identifies the network itself.

Broadcast Address: All host bits set to 1. Used to send packets to all hosts on the network.

The lesson

IPv4 Addressing and CIDR Subnetting

How CIDR prefix lengths split 32-bit IPv4 addresses into Network and Host fields, and how to compute subnet masks, broadcast addresses, and host ranges.

1. IPv4 Structure and CIDR Prefix Notation

An IPv4 address is a 32-bit unsigned integer written in dotted-decimal notation as four 8-bit octets (e.g., 192.168.1.50), where each octet ranges from 0 to 255.

To route packets efficiently, CIDR (Classless Inter-Domain Routing) splits the 32 bits into two contiguous parts using a prefix length /p (from /0 to /32):

  • Network Prefix (first p bits — blue in the simulator): Identifies the subnet (network) as a whole. All devices on the same local subnet share the exact same first p bits.
  • Host Identifier (remaining h = 32 − p bits — grey in the simulator): Identifies an individual interface (host) within that subnet.

The Subnet Mask represents the prefix /p as a 32-bit number with p leading 1s followed by 32 − p trailing 0s:

/24  →  11111111.11111111.11111111.00000000₂  =  255.255.255.0
/26  →  11111111.11111111.11111111.11000000₂  =  255.255.255.192
/20  →  11111111.11111111.11110000.00000000₂  =  255.255.240.0

2. Subnet Formulas: Network, Broadcast, and Usable Range

Given any IPv4 address and prefix /p (with h = 32 − p host bits), every field in the calculator is computed by bitwise operations:

FieldBitwise DefinitionFormula / Meaning
Network AddressSet all h host bits to 0IP AND Mask — identifies the subnet in routing tables (cannot be assigned to a host).
Broadcast AddressSet all h host bits to 1Network OR (~Mask) — delivers a packet to all hosts on the subnet (cannot be assigned to a host).
Total AddressesAll combinations of h host bits2ʰ = 2^(32 − p)
Usable HostsTotal minus Network and Broadcast2^(32 − p) − 2 (for /1 through /30)
Usable Host RangeFirst host to last host(Network + 1) to (Broadcast − 1)

3. Fast Mental Calculation Using Block Size

Instead of converting all 32 bits to binary by hand, use the block size in the octet where the boundary lands:

Block Size = 256 − (Mask value in the boundary octet)

Worked Example 1: 192.168.1.130/26

  • /26 has 26 − 24 = 2 network bits in the 4th octet: 11000000₂ = 192 → Mask is 255.255.255.192.
  • Block Size: 256 − 192 = 64 (or 2⁶ = 64). Subnets in the 4th octet start at multiples of 64: .0, .64, .128, .192.
  • Because 130 falls between 128 and 191:
    • Network Address: 192.168.1.128
    • Broadcast Address: 192.168.1.191 (one less than the next subnet .192)
    • Usable Host Range: 192.168.1.129 – 192.168.1.190 (64 − 2 = 62 usable hosts)

Worked Example 2 (Why two hosts on /25 can't talk directly):
Enter 192.168.1.70 with prefix /25 in the simulator. A /25 has mask 255.255.255.128 and block size 128, splitting 192.168.1.x into two subnets: .0 – .127 and .128 – .255. Host A (.70) is in subnet 192.168.1.0/25, while Host B (.130) is in subnet 192.168.1.128/25. Because (IP_A AND Mask) ≠ (IP_B AND Mask), they cannot communicate at Layer 2 without a router.

Exercises

1. For 172.16.45.130/27, find the Subnet Mask, Block Size, Network Address, Broadcast Address, and Usable Host count, then check in the simulator.

Show solution
/27 puts 3 network bits in the 4th octet (11100000₂ = 224):
• Subnet Mask: 255.255.255.224
• Block Size: 256 − 224 = 32 (blocks start at 0, 32, 64, 96, 128, 160…)
• Network Address: 172.16.45.128
• Broadcast Address: 172.16.45.159
• Usable Hosts: 2⁵ − 2 = 30 (172.16.45.129 – 172.16.45.158).

2. You need to allocate a single subnet for 500 host devices while wasting as few IP addresses as possible. What prefix length /p should you choose?

Show solution
We need 2ʰ − 2 ≥ 500. Since 2⁸ − 2 = 254 (too small) and 2⁹ − 2 = 510 ≥ 500, we need h = 9 host bits → prefix p = 32 − 9 = /23 (subnet mask 255.255.254.0).

Quiz

What dotted-decimal subnet mask corresponds to a /28 prefix?

How many usable host addresses are in a /22 subnet?

Which bitwise operation computes the Network Address from an IP address and its Subnet Mask?

What are the Network and Broadcast addresses for 10.0.0.50/26?