Subnetting is the one topic every CCNA student has to master, and it is also the one most people try to memorize instead of understand. In t...
Subnetting is the one topic every CCNA student has to master, and it is also the one most people try to memorize instead of understand. In this post I will show you the quick method I use for every /24 to /30 problem, give you a cheat table, walk through five worked problems with answers, and finish with a complete VLSM design you can reuse in your own Packet Tracer labs.
Prefer video? Watch more hands-on labs on the Technical Hakim YouTube channel.
What subnetting actually does
An IPv4 address is 32 bits, written as four octets (for example 192.168.10.77). The subnet mask, or prefix length, tells a device which bits identify the network and which bits identify the host inside that network. A /24 means the first 24 bits are network bits and the last 8 bits are host bits.
When you subnet, you "borrow" some of those host bits and turn them into network bits. Each bit you borrow doubles the number of subnets and roughly halves the number of hosts per subnet. That is the whole idea. Everything else is arithmetic.
Two formulas cover almost every exam question:
- Number of subnets = 2s, where s is the number of borrowed bits.
- Usable hosts per subnet = 2h − 2, where h is the number of host bits left. We subtract 2 because the first address is the network address and the last address is the broadcast address.
The block size (magic number) method
For prefixes between /24 and /30, only the last octet changes, so you can work everything out in your head with one number: the block size.
Block size = 256 − the last octet of the subnet mask.
For a /26, the mask is 255.255.255.192, so the block size is 256 − 192 = 64. That means subnets start at 0, 64, 128 and 192. Once you know where each subnet starts, the rest falls out:
- Network address: the multiple of the block size at or just below your host's last octet.
- Broadcast address: the next network address minus 1.
- First usable host: network address + 1.
- Last usable host: broadcast address − 1.
I tell my students to stop converting everything into binary for these prefixes. Binary is how it works underneath, and you should understand it once, but the block size method is faster and less error-prone under exam pressure.
/24 to /30 cheat table
Keep this table next to you while you practice. After a week of problems you will not need it anymore.
| Prefix | Subnet mask | Wildcard mask | Block size | Subnets in a /24 | Total addresses | Usable hosts |
|---|---|---|---|---|---|---|
| /24 | 255.255.255.0 | 0.0.0.255 | 256 | 1 | 256 | 254 |
| /25 | 255.255.255.128 | 0.0.0.127 | 128 | 2 | 128 | 126 |
| /26 | 255.255.255.192 | 0.0.0.63 | 64 | 4 | 64 | 62 |
| /27 | 255.255.255.224 | 0.0.0.31 | 32 | 8 | 32 | 30 |
| /28 | 255.255.255.240 | 0.0.0.15 | 16 | 16 | 16 | 14 |
| /29 | 255.255.255.248 | 0.0.0.7 | 8 | 32 | 8 | 6 |
| /30 | 255.255.255.252 | 0.0.0.3 | 4 | 64 | 4 | 2 |
Notice the pattern: the block size equals the total number of addresses, and the wildcard mask's last octet is always the block size minus 1. You will use wildcard masks later in OSPF network statements and ACLs, so it pays to learn them together.
Five worked problems
Try each problem on paper before you read the answer. That is where the learning happens.
Problem 1: Find the network, broadcast and host range
Question: A host has the address 192.168.10.77/26. What is its network address, broadcast address and usable host range?
Working: /26 means mask 255.255.255.192, so the block size is 64. The subnets in the last octet are 0, 64, 128, 192. The value 77 sits between 64 and 128, so the host belongs to the subnet that starts at 64.
| Item | Answer |
|---|---|
| Network address | 192.168.10.64 |
| First usable host | 192.168.10.65 |
| Last usable host | 192.168.10.126 |
| Broadcast address | 192.168.10.127 |
Problem 2: Create a required number of subnets
Question: You have 192.168.20.0/24 and need at least 6 subnets. Each subnet should have as many hosts as possible. Which prefix do you use, and what are the subnets?
Working: Borrowing 2 bits gives 22 = 4 subnets, which is not enough. Borrowing 3 bits gives 23 = 8 subnets, which is enough. The new prefix is /24 + 3 = /27. That leaves 5 host bits, so 25 − 2 = 30 usable hosts per subnet. Block size is 32.
Answer: Use /27 (255.255.255.224). The eight subnets are 192.168.20.0, .32, .64, .96, .128, .160, .192 and .224. You use six and keep two spare for growth.
Problem 3: Choose a prefix for a host count
Question: A department needs 50 hosts in one subnet. What is the smallest subnet that fits?
Working: Find the smallest h where 2h − 2 is at least 50. With h = 5, you get 30, which is too small. With h = 6, you get 62, which fits. Six host bits means 32 − 6 = 26 network bits.
Answer: /26 (255.255.255.192), giving 62 usable addresses.
Problem 4: Are two hosts on the same subnet?
Question: Host A is 172.16.5.130/28 and Host B is 172.16.5.145/28. Can they talk directly without a router?
Working: /28 has a block size of 16. Subnets in the last octet go 0, 16, 32 ... 128, 144, 160. Host A (130) sits in the 128 subnet, which runs from 128 to 143. Host B (145) sits in the 144 subnet, which runs from 144 to 159.
Answer: No. Host A is in 172.16.5.128/28 and Host B is in 172.16.5.144/28. They are on different subnets and need a router (or a Layer 3 switch) to communicate. This exact situation is a very common "why can't my PCs ping each other" problem in labs.
Problem 5: Point-to-point links with /30
Question: You split 10.1.1.0/24 into /30 subnets for router-to-router links. What are the network address, usable addresses and broadcast address of the fourth /30 subnet?
Working: Block size for /30 is 4. The subnets go 10.1.1.0, 10.1.1.4, 10.1.1.8, 10.1.1.12 ... so the fourth subnet starts at 12.
Answer: Network 10.1.1.12/30, usable hosts 10.1.1.13 and 10.1.1.14, broadcast 10.1.1.15. One router interface gets .13 and the other gets .14.
VLSM example: one /24 for a small branch office
Variable Length Subnet Masking (VLSM) means using different prefix lengths inside the same address block, so each subnet is sized for what it actually needs. Without VLSM, you would have to give every subnet the same size, which wastes addresses on small links.
Scenario: You are given 192.168.50.0/24 for a branch office with these requirements:
- LAN A (Staff): 100 hosts
- LAN B (Students): 50 hosts
- LAN C (Admin): 25 hosts
- LAN D (Servers): 10 hosts
- WAN 1 and WAN 2: point-to-point router links, 2 hosts each
Step 1: Sort from largest to smallest
Always allocate the biggest subnet first. If you start with small subnets, you can end up with gaps that are the wrong size for the larger ones.
Step 2: Pick a prefix for each requirement
- 100 hosts needs 7 host bits (126 usable), so /25.
- 50 hosts needs 6 host bits (62 usable), so /26.
- 25 hosts needs 5 host bits (30 usable), so /27.
- 10 hosts needs 4 host bits (14 usable), so /28.
- 2 hosts needs 2 host bits (2 usable), so /30.
Step 3: Allocate in order
Each new subnet starts right after the previous broadcast address.
| Subnet | Needed | Network / prefix | Mask | Usable range | Broadcast |
|---|---|---|---|---|---|
| LAN A | 100 | 192.168.50.0/25 | 255.255.255.128 | .1 – .126 | .127 |
| LAN B | 50 | 192.168.50.128/26 | 255.255.255.192 | .129 – .190 | .191 |
| LAN C | 25 | 192.168.50.192/27 | 255.255.255.224 | .193 – .222 | .223 |
| LAN D | 10 | 192.168.50.224/28 | 255.255.255.240 | .225 – .238 | .239 |
| WAN 1 | 2 | 192.168.50.240/30 | 255.255.255.252 | .241 – .242 | .243 |
| WAN 2 | 2 | 192.168.50.244/30 | 255.255.255.252 | .245 – .246 | .247 |
The range 192.168.50.248/29 (.248 to .255) is still free. You could use it later for two more /30 links or one small /29 subnet.
Here is how the first gateway would look on a Cisco router if LAN A were connected to GigabitEthernet0/0:
R1(config)# interface gigabitEthernet 0/0
R1(config-if)# description LAN A - Staff
R1(config-if)# ip address 192.168.50.1 255.255.255.128
R1(config-if)# no shutdown
With LAN A's switch connected, show ip interface brief confirms the address and the up/up state:
R1#show ip interface brief
Interface IP-Address OK? Method Status Protocol
GigabitEthernet0/0 192.168.50.1 YES manual up up
GigabitEthernet0/1 unassigned YES unset administratively down down
GigabitEthernet0/2 unassigned YES unset administratively down down
Vlan1 unassigned YES unset administratively down down
Cisco IOS interfaces take the dotted-decimal mask, not the /25 notation, so you must convert the prefix to a mask yourself. That is another reason the cheat table is worth memorizing.
Checking your VLSM work
Do two quick checks before you configure anything:
- Every network address must be a multiple of its own block size. For example, 192.168.50.224/28 is valid because 224 divides evenly by 16. 192.168.50.200/28 would not be valid.
- No two ranges may overlap. Write the network and broadcast addresses one under the other and confirm each network starts after the previous broadcast.
Common mistakes
- Forgetting the minus 2. A /27 has 32 addresses but only 30 usable hosts. Exams love this trap.
- Using the network or broadcast address on a host. In Packet Tracer, if you try to give a router interface 192.168.10.64 with mask 255.255.255.192, IOS rejects it with a "Bad mask" style error because that is the network address itself.
- Allocating small subnets first in VLSM. This leaves gaps that do not line up with the block size of larger subnets.
- Mixing up mask and wildcard. 255.255.255.224 is a mask, 0.0.0.31 is the matching wildcard. Interfaces use masks; OSPF network statements and ACLs use wildcards.
- Mismatched masks between two devices on the same link. If one router uses /30 and the other uses /29, they may still ping but routing protocols such as OSPF will not form a neighbor relationship.
Summary
For /24 to /30 you only need the block size: 256 minus the last mask octet. Use it to find network, broadcast and host ranges in seconds. Use 2s for subnets and 2h − 2 for hosts. For VLSM, sort requirements from largest to smallest, allocate in order, and check that every network sits on a multiple of its block size with no overlaps. Practice ten problems a day for a week and subnetting stops being scary.
Related tutorials
- Inter-VLAN Routing with Router-on-a-Stick (Packet Tracer Lab)
- OSPF Single-Area Configuration: Full Lab with Verification
- Standard vs Extended ACLs on Cisco Routers: Lab with Examples
- DHCP Server on a Cisco Router plus DHCP Relay (ip helper-address)
Sources
- RFC 950, Internet Standard Subnetting Procedure: https://www.rfc-editor.org/rfc/rfc950
- RFC 1878, Variable Length Subnet Table For IPv4: https://www.rfc-editor.org/rfc/rfc1878
- RFC 4632, Classless Inter-domain Routing (CIDR): https://www.rfc-editor.org/rfc/rfc4632
- RFC 1918, Address Allocation for Private Internets: https://www.rfc-editor.org/rfc/rfc1918
- Cisco IOS IP Addressing Configuration Guide
No comments