Subnetting: Network, Broadcast & Host Range Calculation
Interview Question: "Given the IP address
192.168.10.75with subnet mask255.255.255.192(/26), determine the network address, broadcast address, range of valid host addresses, and total usable hosts. Show both the formal binary breakdown and the rapid 'Magic Number' interview shortcut."
1. Executive Summary & Parameter Breakdown
Subnetting divides a single contiguous IP network block into smaller, isolated broadcast domains to minimize traffic congestion, enforce firewall security boundaries, and reduce address waste.
Problem Parameters:
- Given IPv4 Address:
192.168.10.75 - Subnet Mask:
255.255.255.192 - CIDR Prefix Length:
/26( network bits) - The "Interesting Octet": Octet 4 (
75and192). The first three octets (255.255.255) contain all 1s, meaning the network prefix192.168.10.remains completely locked and unchanged.
2. Method 1: The Formal Binary Bitwise Breakdown
In academic and deep-dive technical interviews, you are expected to demonstrate how network hardware (routers and L3 switches) evaluates addresses at the bit level.
Step 1: Convert the 4th Octet to Binary
- IP Octet 4 (75):
0100 1011() - Mask Octet 4 (192):
1100 0000()
The first 2 bits (11) belong to the network prefix. The remaining 6 bits (000000) are allocated for host addressing ().
Step 2: Bitwise AND to Find Network Address
The router applies a bitwise AND operation between the IP address and the subnet mask. Any bit ANDed with 0 becomes 0, zeroing out the host portion:
IP (4th Octet): 0 1 0 0 1 0 1 1 (75)
Mask (4th Octet): & 1 1 0 0 0 0 0 0 (192)
-----------------------------------
Network Result: 0 1 0 0 0 0 0 0 (= 64 in decimal)
Step 3: Set Host Bits to 1 to Find Broadcast Address
The directed broadcast address addresses every host on the subnet. It is generated by setting all 6 host bits to 1s:
Network Bits: 0 1 _ _ _ _ _ _
Host Bits to 1: 0 1 1 1 1 1 1 1 (= 64 + 32 + 16 + 8 + 4 + 2 + 1 = 127)
Step 4: Calculate Valid Host Range and Capacity
- First Usable Host: Network Address + 1
192.168.10.65 - Last Usable Host: Broadcast Address - 1
192.168.10.126 - Total Usable Hosts Formula:
Why Subtract 2? The first address in the block (all host bits 0) represents the Network Identifier itself, and the final address (all host bits 1) is reserved for the Directed Broadcast. Neither can be assigned to a host NIC.
3. Method 2: The 5-Second "Magic Number" Shortcut
In live coding and whiteboard interviews, converting decimal numbers to binary takes too much time. Professional network engineers use the Magic Number (Block Size) method:
Step 1: Identify the "Interesting Octet" (the one not 255 or 0)
Octet 4: Mask value is 192.
Step 2: Calculate Magic Number (Block Size):
Magic Number = 256 - Mask Octet
Magic Number = 256 - 192 = 64
Step 3: List Multiples of the Magic Number starting at 0:
0, 64, 128, 192...
Step 4: Find where the IP (75) lands:
75 sits between 64 and 128.
├── Network Address: 192.168.10.64 (The lower boundary)
├── Next Subnet: 192.168.10.128
├── Broadcast Address: 192.168.10.127 (Next subnet - 1)
├── First Usable Host: 192.168.10.65 (Network + 1)
└── Last Usable Host: 192.168.10.126 (Broadcast - 1)
4. Fast-Reference CIDR Subnet Cheat Sheet (/24 to /30)
| CIDR Prefix | Subnet Mask | Host Bits () | Magic Number (Block Size) | Total IPs () | Usable Hosts () | Primary Use Case |
|---|---|---|---|---|---|---|
| /24 | 255.255.255.0 | 8 | 256 | 256 | 254 | Standard small office / LAN. |
| /25 | 255.255.255.128 | 7 | 128 | 128 | 126 | Half-C department network. |
| /26 | 255.255.255.192 | 6 | 64 | 64 | 62 | Quarter-C team subnet. |
| /27 | 255.255.255.224 | 5 | 32 | 32 | 30 | Small branch or server cluster. |
| /28 | 255.255.255.240 | 4 | 16 | 16 | 14 | DMZ or management subnet. |
| /29 | 255.255.255.248 | 3 | 8 | 8 | 6 | Small public static IP block. |
| /30 | 255.255.255.252 | 2 | 4 | 4 | 2 | Point-to-Point WAN router links. |
5. Critical Interview Traps & RFC Edge Cases
- RFC 3021 (/31 Subnets for Point-to-Point Links):
- In traditional networking, a
/31mask has usable hosts. - However, RFC 3021 allows point-to-point router links to use
/31prefixes () with 2 usable hosts, treating the first address as host 0 and second as host 1 without dedicated network or broadcast addresses. This saves millions of IPv4 addresses on backbone transit links.
- In traditional networking, a
- Host Routes (/32):
- A
/32prefix () has 0 host bits and represents a single specific endpoint (e.g., a loopback interface or VPN client tunnel).
- A
- Subnetting Across Octet Boundaries (/22, /23):
- When the mask is in the 3rd octet (e.g.
255.255.252.0/22), the magic number is . Subnet boundaries increment by 4 in the 3rd octet (172.16.0.0,172.16.4.0,172.16.8.0...).
- When the mask is in the 3rd octet (e.g.
6. Python Verification: Subnet Calculator
The following executable Python script implements subnet boundary calculations using raw bitwise arithmetic and verifies them against Python's standard ipaddress module:
"""
IPv4 Subnet Calculator & Verification Suite
Computes network address, broadcast address, valid host range, and capacity.
"""
import ipaddress
def calculate_subnet_bitwise(ip_str: str, mask_str: str) -> dict:
ip_parts = [int(x) for x in ip_str.split(".")]
mask_parts = [int(x) for x in mask_str.split(".")]
# Bitwise AND for network address
net_parts = [ip_parts[i] & mask_parts[i] for i in range(4)]
# Invert mask bits for broadcast address
inv_mask = [255 - mask_parts[i] for i in range(4)]
bcast_parts = [net_parts[i] | inv_mask[i] for i in range(4)]
# Format strings
network_addr = ".".join(map(str, net_parts))
broadcast_addr = ".".join(map(str, bcast_parts))
# Host ranges
first_host_parts = net_parts[:]
first_host_parts[3] += 1
last_host_parts = bcast_parts[:]
last_host_parts[3] -= 1
# Total usable hosts
total_zeros = sum(bin(m).count("0") - 2 for m in mask_parts) # Count zero bits
# Compensate for 8-bit octet formatting
zero_bits = sum(8 - bin(m).count("1") for m in mask_parts)
usable_hosts = (2 ** zero_bits) - 2
return {
"network": network_addr,
"broadcast": broadcast_addr,
"first_host": ".".join(map(str, first_host_parts)),
"last_host": ".".join(map(str, last_host_parts)),
"usable_hosts": usable_hosts,
"host_bits": zero_bits
}
if __name__ == "__main__":
ip_input = "192.168.10.75"
mask_input = "255.255.255.192"
print("=" * 65)
print("IPV4 SUBNETTING CALCULATION VERIFICATION")
print(f"Target IP: {ip_input} | Subnet Mask: {mask_input}")
print("=" * 65)
# 1. Bitwise Algorithm
res = calculate_subnet_bitwise(ip_input, mask_input)
print(f"Network Address: {res['network']}")
print(f"Broadcast Address: {res['broadcast']}")
print(f"Usable Host Range: {res['first_host']} - {res['last_host']}")
print(f"Total Usable Hosts: {res['usable_hosts']} (2^{res['host_bits']} - 2)")
# 2. Standard Library Cross-Verification
net_obj = ipaddress.IPv4Network(f"{ip_input}/{mask_input}", strict=False)
print(f"\n--- Python ipaddress Library Cross-Check ---")
print(f"Network: {net_obj.network_address}")
print(f"Broadcast: {net_obj.broadcast_address}")
print(f"Hosts Available: {net_obj.num_addresses - 2}")
assert str(net_obj.network_address) == res["network"]
assert str(net_obj.broadcast_address) == res["broadcast"]
assert (net_obj.num_addresses - 2) == res["usable_hosts"]
print("\nSUCCESS: All subnetting calculations mathematically verified.")