IPv4 Subnetting – Network and Host Portions, CIDR, and Address Calculation
1. IPv4 Address Structure
An IPv4 address is a 32-bit number written as four decimal values separated by dots — each value representing 8 bits (one octet). Understanding the binary representation of an IP address is the foundation of all subnetting calculations.
Related pages: IP Addressing | IP Classes | Subnetting Basics | Subnetting | Wildcard Masks | Private vs Public IP | ipconfig & ifconfig | MAC vs IP | Static NAT | Dynamic NAT | Routers | Route Summarization | IPv6 Addressing
2. Network and Host Portions
Every IPv4 address is divided into two logical portions by the subnet mask: the network portion (which identifies the network the address belongs to) and the host portion (which identifies the specific device within that network). The subnet mask uses 1-bits to mark the network portion and 0-bits to mark the host portion.
Classful Addressing — Default Subnet Masks
Before CIDR (Classless Inter-Domain Routing), IPv4 addresses were assigned to three main classes with fixed default masks. Modern networks use CIDR but classful knowledge is still tested in the CCNA. See also IP Classes:
| Class | First Octet Range | Leading Bits | Default Mask | CIDR | Network / Host | Usable Hosts |
|---|---|---|---|---|---|---|
| A | 1 – 126 | 0xxx xxxx | 255.0.0.0 | /8 | N.H.H.H | 16,777,214 |
| B | 128 – 191 | 10xx xxxx | 255.255.0.0 | /16 | N.N.H.H | 65,534 |
| C | 192 – 223 | 110x xxxx | 255.255.255.0 | /24 | N.N.N.H | 254 |
| D | 224 – 239 | 1110 xxxx | N/A | N/A | Multicast (not assignable) | — |
| E | 240 – 255 | 1111 xxxx | N/A | N/A | Reserved/Experimental | — |
Note: 127.x.x.x (loopback range) is excluded from Class A assignable addresses. 127.0.0.1 is always the localhost loopback address. See Private vs Public IP for reserved ranges.
3. Subnet Masks and CIDR Notation
A subnet mask is a 32-bit value that uses consecutive 1-bits from the left to mark the network portion, followed by consecutive 0-bits for the host portion. There are no gaps — the 1-bits are always contiguous.
CIDR (Classless Inter-Domain Routing) notation expresses
the subnet mask as a prefix length — the number of leading 1-bits
— written after a slash: 192.168.10.5/24 means
the first 24 bits are the network portion.
4. Finding the Network Address — Bitwise AND
The network address (also called the subnet address) is found by performing a bitwise AND operation between the IP address and the subnet mask. AND rules: 1 AND 1 = 1; 1 AND 0 = 0; 0 AND 0 = 0. The result has all host bits set to zero.
Worked Example — Non-Octet Boundary (/20)
5. Finding the Broadcast Address
The broadcast address is the last address in the subnet — all host bits are set to 1. Frames sent to the broadcast address are received by every device in the subnet. The broadcast address cannot be assigned to a device.
6. Usable Host Range and the 2^n − 2 Formula
The usable host range is the set of addresses that can be assigned to devices. The first address (all host bits = 0) is the network address; the last (all host bits = 1) is the broadcast address. Both are reserved and cannot be used for device assignment.
7. Subnetting — Borrowing Bits
Subnetting divides a larger network into smaller sub-networks by borrowing bits from the host portion and adding them to the network portion. Each borrowed bit doubles the number of subnets and halves the number of hosts per subnet.
| Borrowed Bits | Subnets Created (2^n) | New CIDR (from /24) | Host Bits Left | Usable Hosts (2^h−2) | Block Size | Subnet Mask |
|---|---|---|---|---|---|---|
| 1 | 2 | /25 | 7 | 126 | 128 | 255.255.255.128 |
| 2 | 4 | /26 | 6 | 62 | 64 | 255.255.255.192 |
| 3 | 8 | /27 | 5 | 30 | 32 | 255.255.255.224 |
| 4 | 16 | /28 | 4 | 14 | 16 | 255.255.255.240 |
| 5 | 32 | /29 | 3 | 6 | 8 | 255.255.255.248 |
| 6 | 64 | /30 | 2 | 2 | 4 | 255.255.255.252 |
8. The Block Size Method — Fast Subnetting
The block size method is the fastest way to find subnet boundaries without converting every octet to binary. The block size is the increment between consecutive subnet network addresses.
9. VLSM — Variable Length Subnet Masking
VLSM allows different subnets within the same network to use different prefix lengths — allocating exactly the right number of host addresses for each requirement rather than using the same size everywhere. This maximises efficient use of the address space.
10. Common Subnet Reference Table
| CIDR | Subnet Mask | Network Bits | Host Bits | Block Size | Addresses | Usable Hosts | Typical Use |
|---|---|---|---|---|---|---|---|
| /8 | 255.0.0.0 | 8 | 24 | — | 16,777,216 | 16,777,214 | Class A network |
| /16 | 255.255.0.0 | 16 | 16 | — | 65,536 | 65,534 | Class B / large enterprise |
| /24 | 255.255.255.0 | 24 | 8 | 1 (in octet 3) | 256 | 254 | Standard office LAN |
| /25 | 255.255.255.128 | 25 | 7 | 128 | 128 | 126 | Medium LAN |
| /26 | 255.255.255.192 | 26 | 6 | 64 | 64 | 62 | Department subnet |
| /27 | 255.255.255.224 | 27 | 5 | 32 | 32 | 30 | Small department |
| /28 | 255.255.255.240 | 28 | 4 | 16 | 16 | 14 | Small workgroup |
| /29 | 255.255.255.248 | 29 | 3 | 8 | 8 | 6 | Very small segment |
| /30 | 255.255.255.252 | 30 | 2 | 4 | 4 | 2 | Point-to-point WAN links |
| /31 | 255.255.255.254 | 31 | 1 | 2 | 2 | 2* | P2P links (RFC 3021 — no broadcast) |
| /32 | 255.255.255.255 | 32 | 0 | 1 | 1 | 1* | Host route, loopback |
* /31 and /32 are special cases: /31 is used for point-to-point links (RFC 3021) with no network or broadcast address; /32 is a host route (identifies a single specific address — used for loopback interfaces and static host routes).
11. Fully Worked Exam Example
Work through this example completely without a calculator — the method used here matches the speed needed for CCNA exam conditions.
12. Common Subnetting Mistakes
| Mistake | Example of the Error | Correct Approach |
|---|---|---|
| Forgetting to subtract 2 for network and broadcast | /24 → says 256 hosts instead of 254 | Always apply 2^(host bits) − 2 |
| Using the IP address as the network address | Saying network = 172.16.50.123 when it is 172.16.48.0 | Perform bitwise AND or use block size to find the correct network address |
| Confusing subnet mask with wildcard mask | Wildcard mask 0.0.0.255 is NOT the same as subnet mask 255.255.255.0 — wildcards are used in ACLs and OSPF network statements (inverse of the subnet mask) | Wildcard = 255.255.255.255 − subnet mask |
| Forgetting that /31 and /32 are special cases | Applying the 2^n−2 formula to /30 and getting 2, then using the same formula for /31 and getting 0 | /30 gives 2 usable hosts; /31 (RFC 3021) gives 2 usable on P2P links with no reserved addresses; /32 is a host route |
| Miscounting borrowed bits | Starting with /24, borrowing 3 bits, and thinking the new prefix is /27 but calculating hosts using 5 host bits instead of 5 (32-27=5 — this one is actually correct, but confusion about which number to use is common) | Host bits = 32 − new prefix length. New prefix = old prefix + borrowed bits |
| Not aligning to block boundaries | Assuming 172.16.50.123/20 has network address 172.16.50.0 instead of 172.16.48.0 | Find the nearest multiple of the block size in the interesting octet that is ≤ the IP's octet value |
13. Exam Tips & Key Points
- An IPv4 address is 32 bits, divided into four 8-bit octets. IPv6 is 128 bits — do not confuse the two.
- The subnet mask uses consecutive 1-bits (network portion) followed by consecutive 0-bits (host portion). The prefix length (/n) counts the 1-bits.
- The network address = IP AND subnet mask (all host bits = 0). The broadcast address = network address with all host bits = 1.
- Usable hosts per subnet = 2^(host bits) − 2. The "−2" accounts for the network address and broadcast address.
- The block size method is the fastest exam technique: block size = 256 − interesting octet. Find the nearest multiple of block size ≤ the IP's octet.
- Number of subnets when borrowing bits = 2^(borrowed bits). Hosts per new subnet = 2^(remaining host bits) −2.
- Know the critical prefix lengths by memory: /30 = 2 usable (P2P links), /29 = 6 usable, /28 = 14 usable, /27 = 30 usable, /26 = 62 usable, /25 = 126 usable, /24 = 254 usable.
- Wildcard mask = 255.255.255.255 − subnet mask.
A /24 wildcard = 0.0.0.255 (used in OSPF
networkstatements and ACLs). - VLSM allocates differently-sized subnets from a single block — assign largest subnets first to avoid fragmentation. Essential for route summarization.
- Class A = first octet 1–126; Class B = 128–191; Class C = 192–223. 127.x.x.x is the loopback range. See also Private vs Public IP.
14. Summary Reference Table
| Concept | Formula / Rule |
|---|---|
| IPv4 address size | 32 bits (4 octets × 8 bits) |
| Network address | IP AND subnet mask (all host bits = 0) |
| Broadcast address | Network address with all host bits set to 1 |
| First usable host | Network address + 1 |
| Last usable host | Broadcast address − 1 |
| Usable hosts per subnet | 2^(host bits) − 2 |
| Host bits | 32 − prefix length |
| Number of subnets | 2^(borrowed bits) |
| Block size | 256 − interesting octet of subnet mask |
| Wildcard mask | 255.255.255.255 − subnet mask |
| Class A default mask | 255.0.0.0 (/8) |
| Class B default mask | 255.255.0.0 (/16) |
| Class C default mask | 255.255.255.0 (/24) |
IPv4 Subnetting Quiz
Related Topics & Step-by-Step Tutorials
Continue building your subnetting and addressing knowledge:
- Subnetting Basics — conceptual intro before diving into calculations
- Subnetting — additional subnetting practice and methods
- IP Addressing — full IPv4 address structure and assignment
- IP Classes — Class A, B, C, D, E ranges and default masks
- Wildcard Masks — used in OSPF and ACLs; inverse of subnet masks
- Private vs Public IP — RFC 1918 reserved ranges (10.x, 172.16–31.x, 192.168.x)
- Private vs Public IP (detailed)
- Route Summarization — applying VLSM knowledge to aggregate routes
- NAT Overview — how private subnets reach the internet
- Dynamic NAT — pool-based translation of subnets
- Static NAT — one-to-one host mapping
- PAT — many-to-one overloading (most common in home/office)
- DHCP Overview — automatic IP assignment within subnets
- DHCP Server Configuration — configuring scopes aligned to your subnets
- OSPF Overview — uses subnet masks and wildcard masks extensively
- OSPF Single-Area Configuration
- ACL Overview — ACLs use wildcard masks derived from subnet masks
- IPv6 Addressing — the 128-bit successor to IPv4 subnetting
- IPv6 Basic Configuration
- Route Summarization & Aggregation — VLSM in practice
- ipconfig / ifconfig — verify subnet mask and IP on a host
- show ip interface brief — verify IP assignments on router interfaces