Subnetting – Concepts, Calculations & Step-by-Step Examples
1. What Is Subnetting?
Subnetting is the process of dividing a single IP network into smaller logical sub-networks called subnets. It works by borrowing bits from the host portion of an IP address and reassigning them as additional network bits, creating more (but smaller) networks from one original block.
Every time you borrow one bit, you double the number of subnets and halve the number of hosts per subnet. The tradeoff is always: more subnets = fewer hosts per subnet.
- Improves organisation — different departments, floors, or functions get their own subnet
- Enhances security — subnets are isolated; a firewall or ACL between them controls traffic
- Reduces broadcast domains — broadcasts are confined within a subnet, improving performance
- Conserves IP addresses — allocate only as many IPs as a segment actually needs
- Simplifies routing — route summarisation (supernetting) condenses multiple subnets into one routing table entry
Related pages: IP Interface Brief | IPv6 | VLANs | NAT | Wildcard Masks | Default Routes | Static Routing Configuration | Private vs Public IP Addresses
2. IP Address Structure Refresher
An IPv4 address is 32 bits long, written as four 8-bit octets in dotted-decimal notation. Every IPv4 address has two logical parts:
IP address: 192 . 168 . 10 . 5
Binary: 11000000 . 10101000 . 00001010 . 00000101
--------
Subnet mask: 255 . 255 . 255 . 0
Binary: 11111111 . 11111111 . 11111111 . 00000000
|<------------ Network (24 bits) ---------->| |<Host (8 bits)>|
Network address: 192.168.10.0 (all host bits = 0)
Broadcast address: 192.168.10.255 (all host bits = 1)
Valid host range: 192.168.10.1 – 192.168.10.254
The subnet mask determines the boundary. Bits set to 1 in the mask are the network portion; bits set to 0 are the host portion.
3. Subnet Masks – Dotted Decimal, Binary, and CIDR
The same subnet mask can be written three ways. All three are equivalent and you need to be comfortable converting between them for the CCNA exam.
| CIDR Prefix | Dotted Decimal | Binary (last octet) | Host Bits Remaining | Usable Hosts |
|---|---|---|---|---|
| /24 | 255.255.255.0 | 00000000 | 8 | 254 |
| /25 | 255.255.255.128 | 10000000 | 7 | 126 |
| /26 | 255.255.255.192 | 11000000 | 6 | 62 |
| /27 | 255.255.255.224 | 11100000 | 5 | 30 |
| /28 | 255.255.255.240 | 11110000 | 4 | 14 |
| /29 | 255.255.255.248 | 11111000 | 3 | 6 |
| /30 | 255.255.255.252 | 11111100 | 2 | 2 |
| /32 | 255.255.255.255 | 11111111 | 0 | 1 (host route) |
Default classful masks: Class A = /8 (255.0.0.0), Class B = /16 (255.255.0.0), Class C = /24 (255.255.255.0).
4. How Subnetting Works – Borrowing Bits
Subnetting works by moving the boundary between the network and host portions to the right — this is called borrowing host bits. Each bit borrowed:
- Doubles the number of available subnets
- Halves the number of hosts per subnet
- Increases the CIDR prefix length by one (e.g., /24 → /25 → /26)
Original /24 network: 192.168.10.0/24
|<-- 24 network bits -->|<--- 8 host bits --->|
Borrow 2 bits for subnetting:
|<-- 24 network bits -->|nn|<--- 6 host bits --->|
^ ^ borrowed subnet bits
New prefix: /26 Subnets: 2² = 4 Hosts: 2&sup6; − 2 = 62
| Bits Borrowed | New Prefix (from /24) | Subnets Created (2^n) | Hosts per Subnet (2^h − 2) | Block Size |
|---|---|---|---|---|
| 1 | /25 | 2 | 126 | 128 |
| 2 | /26 | 4 | 62 | 64 |
| 3 | /27 | 8 | 30 | 32 |
| 4 | /28 | 16 | 14 | 16 |
| 5 | /29 | 32 | 6 | 8 |
| 6 | /30 | 64 | 2 | 4 |
5. The Two Key Formulas
| What You Need | Formula | Variable | Example |
|---|---|---|---|
| Number of subnets | 2n | n = bits borrowed from the host portion | Borrow 3 bits: 2³ = 8 subnets |
| Usable hosts per subnet | 2h − 2 | h = host bits remaining after borrowing; subtract 2 for the network address (all host bits 0) and the broadcast address (all host bits 1) | /27 leaves 5 host bits: 2&sup5; − 2 = 30 hosts |
| Block size / subnet increment | 256 − last non-zero octet of mask | — | Mask 255.255.255.192: 256 − 192 = 64 (subnets start at .0, .64, .128, .192) |
Why subtract 2? Every subnet has two reserved addresses: the network address (all host bits set to 0 — identifies the subnet itself) and the broadcast address (all host bits set to 1 — used to reach all hosts in the subnet simultaneously). Neither can be assigned to a device.
6. Worked Example 1 – Subnetting a Class C Network into 4 Subnets
Given: 192.168.10.0/24 — divide into 4 equal subnets.
- How many bits to borrow? Need 4 subnets → 2² = 4, so borrow 2 bits.
- New prefix: /24 + 2 = /26 — mask 255.255.255.192
- Block size: 256 − 192 = 64
- Hosts per subnet: 2&sup6; − 2 = 62
| Subnet | Network Address | First Host | Last Host | Broadcast |
|---|---|---|---|---|
| 1 | 192.168.10.0/26 | 192.168.10.1 | 192.168.10.62 | 192.168.10.63 |
| 2 | 192.168.10.64/26 | 192.168.10.65 | 192.168.10.126 | 192.168.10.127 |
| 3 | 192.168.10.128/26 | 192.168.10.129 | 192.168.10.190 | 192.168.10.191 |
| 4 | 192.168.10.192/26 | 192.168.10.193 | 192.168.10.254 | 192.168.10.255 |
7. Worked Example 2 – Subnetting a Class C Network into 8 Subnets (/27)
Given: 192.168.10.0/24 — divide into 8 subnets.
- Bits to borrow: 2³ = 8 → borrow 3 bits
- New prefix: /24 + 3 = /27 — mask 255.255.255.224
- Block size: 256 − 224 = 32
- Hosts per subnet: 2&sup5; − 2 = 30
| Subnet | Network | First Host | Last Host | Broadcast |
|---|---|---|---|---|
| 1 | 192.168.10.0/27 | .1 | .30 | .31 |
| 2 | 192.168.10.32/27 | .33 | .62 | .63 |
| 3 | 192.168.10.64/27 | .65 | .94 | .95 |
| 4 | 192.168.10.96/27 | .97 | .126 | .127 |
| 5 | 192.168.10.128/27 | .129 | .158 | .159 |
| 6 | 192.168.10.160/27 | .161 | .190 | .191 |
| 7 | 192.168.10.192/27 | .193 | .222 | .223 |
| 8 | 192.168.10.224/27 | .225 | .254 | .255 |
8. Worked Example 3 – Subnetting a Class B Network (/20)
Given: 172.16.0.0/16 — borrow 4 bits from the host portion.
- New prefix: /16 + 4 = /20 — mask 255.255.240.0
- Subnets: 2&sup4; = 16
- Host bits remaining: 32 − 20 = 12
- Hosts per subnet: 212 − 2 = 4,094
- Block size in third octet: 256 − 240 = 16
| Subnet | Network Address | First Host | Last Host | Broadcast |
|---|---|---|---|---|
| 1 | 172.16.0.0/20 | 172.16.0.1 | 172.16.15.254 | 172.16.15.255 |
| 2 | 172.16.16.0/20 | 172.16.16.1 | 172.16.31.254 | 172.16.31.255 |
| 3 | 172.16.32.0/20 | 172.16.32.1 | 172.16.47.254 | 172.16.47.255 |
| … | … | … | … | … |
| 16 | 172.16.240.0/20 | 172.16.240.1 | 172.16.255.254 | 172.16.255.255 |
9. VLSM – Variable Length Subnet Masking
VLSM allows different subnets within the same network to use different prefix lengths, so each segment gets exactly the number of addresses it needs — no more, no less. This is in contrast to classful or fixed-length subnetting where every subnet is the same size.
VLSM design rule: always allocate the largest subnet first, then carve out smaller ones from the remaining address space.
Example: Design subnets for 192.168.1.0/24 with
these requirements: Dept A needs 50 hosts, Dept B needs 20 hosts,
Dept C needs 10 hosts, WAN link needs 2 hosts.
| Segment | Hosts Needed | Prefix | Subnet Assigned | Usable Hosts |
|---|---|---|---|---|
| Dept A | 50 | /26 | 192.168.1.0/26 | 62 |
| Dept B | 20 | /27 | 192.168.1.64/27 | 30 |
| Dept C | 10 | /28 | 192.168.1.96/28 | 14 |
| WAN link | 2 | /30 | 192.168.1.112/30 | 2 |
Total addresses used: 64 + 32 + 16 + 4 = 116 addresses out of 256. Remaining space: 192.168.1.116 onward, available for future subnets. A fixed /26 for every segment would have wasted the 30-address Dept B block, the 14-address Dept C block, and the 62-address WAN link.
10. CIDR and Route Aggregation (Supernetting)
CIDR (Classless Inter-Domain Routing) removes the rigid
Class A/B/C boundaries and uses prefix length notation (e.g.,
/22) to represent any subnet size. CIDR also enables
route aggregation (also called supernetting or route
summarisation): multiple contiguous subnets are summarised into a
single routing table entry, reducing router memory usage and speeding
up routing.
Four contiguous /24 networks:
192.168.0.0/24
192.168.1.0/24
192.168.2.0/24
192.168.3.0/24
Summarised to one entry:
192.168.0.0/22 (covers all four /24s)
Binary check — the first 22 bits are identical:
192.168.00000000.0 → 192.168.0.0
192.168.00000001.0 → 192.168.1.0
192.168.00000010.0 → 192.168.2.0
192.168.00000011.0 → 192.168.3.0
^^^^^^ — bits 23–24 vary; all others match → /22 summary
Route aggregation is only possible when the subnets are contiguous and the summary address boundary aligns on the correct bit boundary.
11. Subnet Zero and All-Ones Subnet
In early subnetting (RFC 950), the first subnet (subnet zero —
all subnet bits set to 0) and the last subnet (all-ones subnet —
all subnet bits set to 1) were reserved and not usable. Modern IOS and
all current practice treat both as fully usable, enabled by the Cisco
IOS default command ip subnet-zero.
| Subnet | Subnet Bits | Legacy Status | Modern Status |
|---|---|---|---|
| Subnet zero | All 0s | Reserved (unusable) | Usable — ip subnet-zero is on by default in IOS |
| All-ones subnet | All 1s | Reserved (unusable) | Usable in all modern equipment |
The worked examples in this guide already include both subnet zero (e.g., 192.168.10.0/27) and the all-ones subnet (e.g., 192.168.10.224/27) as valid usable subnets.
12. Private IP Address Subnetting
The three private IP ranges (RFC 1918) are the most commonly subnetted address spaces:
| Range | CIDR | Class | Total Addresses | Common Use |
|---|---|---|---|---|
| 10.0.0.0 – 10.255.255.255 | 10.0.0.0/8 | A | 16,777,216 | Large enterprises, data centres; highly flexible for subnetting |
| 172.16.0.0 – 172.31.255.255 | 172.16.0.0/12 | B | 1,048,576 | Medium enterprises; 16 Class B blocks |
| 192.168.0.0 – 192.168.255.255 | 192.168.0.0/16 | C | 65,536 | Small offices and home networks; 256 Class C blocks |
Private addresses are not routable on the public Internet. A NAT device translates them to a public IP for external connectivity. See: NAT.
13. Troubleshooting Subnetting Issues
| Problem | Symptom | Cause | Fix |
|---|---|---|---|
| Overlapping subnets | Routing loops; packets delivered to wrong host; router may reject config | Two subnets share address space (e.g., 192.168.1.0/24 and 192.168.1.0/25 assigned to different segments) | Recalculate subnet ranges; use VLSM carefully ensuring no overlap; verify with a subnet calculator |
| Misconfigured subnet mask | Devices on the same physical segment cannot communicate; host pings fail with “destination unreachable” | Host configured with wrong mask (e.g., /24 instead of /26) so it places other hosts in a different subnet | Check mask on each device with show ip interface brief or ipconfig /all; correct to match the subnet design |
| Using network or broadcast address as host | Unpredictable behaviour; ARP issues; connectivity failures | Administrator assigned the first (.0) or last (.255) address of a subnet to a device | Reassign the device to a valid host address; remember: first = network, last = broadcast |
| Wrong default gateway | Host can reach local subnet but not remote networks or the Internet | Default gateway IP is on a different subnet than the host, or points to the wrong router interface | Confirm the default gateway is an IP in the same subnet as the host and belongs to the router’s interface on that segment |
| VLSM overlap during design | Some hosts unreachable; routing table entries conflict | Subnets carved from the same block were not tracked carefully, causing two subnets to overlap | Always work from largest to smallest subnet and track each allocated block; use a VLSM chart |
14. Key Points & CCNA Exam Tips
- Subnetting borrows bits from the host portion of an address, increasing the prefix length and creating more (smaller) subnets
- Subnets formula: 2n where n = bits borrowed
- Usable hosts formula: 2h − 2 where h = remaining host bits; the −2 removes the network address (all host bits 0) and broadcast address (all host bits 1)
- Block size (subnet increment) = 256 − last non-zero value in the mask’s interesting octet; subnets start at 0, then increment by the block size
- Memorise the eight key /24 subnets and their properties: /25 (126 hosts), /26 (62), /27 (30), /28 (14), /29 (6), /30 (2) — /30 is standard for point-to-point links
- CIDR prefix notation counts the number of 1 bits in the subnet mask: 255.255.255.192 has 26 ones → /26
- VLSM assigns different prefix lengths to different subnets within one network; always allocate the largest subnet first
- Route aggregation (supernetting) combines contiguous subnets into a shorter prefix; check binary alignment before summarising
- Subnet zero (all subnet bits 0) and the all-ones subnet are both usable in modern IOS (
ip subnet-zerois on by default) - Private RFC 1918 ranges: 10.0.0.0/8, 172.16.0.0/12, 192.168.0.0/16 — not routable on the public Internet without NAT
- The most common subnetting mistake on the CCNA exam is forgetting to subtract 2 for host calculations, or misidentifying the broadcast address as a valid host