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
pbits — blue in the simulator): Identifies the subnet (network) as a whole. All devices on the same local subnet share the exact same firstpbits. - Host Identifier (remaining
h = 32 − pbits — 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:
| Field | Bitwise Definition | Formula / Meaning |
|---|---|---|
| Network Address | Set all h host bits to 0 | IP AND Mask — identifies the subnet in routing tables (cannot be assigned to a host). |
| Broadcast Address | Set all h host bits to 1 | Network OR (~Mask) — delivers a packet to all hosts on the subnet (cannot be assigned to a host). |
| Total Addresses | All combinations of h host bits | 2ʰ = 2^(32 − p) |
| Usable Hosts | Total minus Network and Broadcast | 2^(32 − p) − 2 (for /1 through /30) |
| Usable Host Range | First 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
/26has26 − 24 = 2network bits in the 4th octet:11000000₂ = 192→ Mask is255.255.255.192.- Block Size:
256 − 192 = 64(or2⁶ = 64). Subnets in the 4th octet start at multiples of 64:.0, .64, .128, .192. - Because
130falls between128and191:- 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 = 62usable hosts)
- Network Address:
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
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?
/28 has 4 network bits in the 4th octet: 11110000₂ = 128 + 64 + 32 + 16 = 240.
How many usable host addresses are in a /22 subnet?
h = 32 − 22 = 10 host bits → 2¹⁰ − 2 = 1,024 − 2 = 1,022 usable hosts.
Which bitwise operation computes the Network Address from an IP address and its Subnet Mask?
Bitwise AND preserves the 1-masked network bits and clears all 0-masked host bits to 0.
What are the Network and Broadcast addresses for 10.0.0.50/26?
/26 has block size 2⁶ = 64 in the 4th octet, so the first block spans 10.0.0.0 (Network) to 10.0.0.63 (Broadcast).