How to Create IPv4 Subnets
Learn IPv4 subnetting step by step: calculate masks, CIDR prefixes, block sizes, network ranges, usable hosts, broadcasts, FLSM, VLSM, and verification.
Subnetting divides one IPv4 network into smaller logical networks. This lesson explains how to calculate subnet masks, network addresses, usable host ranges, broadcast addresses, equal-size subnets, and variable-size subnets.
Before beginning, understand dotted-decimal IPv4 notation, binary numbers and powers of two, router and switch interfaces, default gateways, and the difference between local and routed traffic.
Why Subnet a Network?
An IPv4 subnet is a logical division of a larger IP network with its own network prefix and address range. A routed subnet normally forms a Layer 2 broadcast boundary: broadcasts from one subnet are not forwarded into another subnet by a router.
- Address conservation: Allocate address space according to the number of devices instead of giving every segment a large network.
- Organization: Separate departments, locations, server networks, management networks, and user networks.
- Security boundaries: Apply firewall rules, access control lists, and routing policies between subnets.
- Routing efficiency: Use structured address plans and, where appropriate, route summarization.
- Reduced broadcast traffic: Broadcasts remain within a smaller broadcast domain.
A VLAN is a Layer 2 segmentation mechanism on switches. A subnet is an IP-layer addressing division. They are different concepts, but they are commonly paired: one VLAN usually maps to one IP subnet, and a router or Layer 3 switch routes between them. See trunk ports and router-on-a-stick for VLAN transport and inter-VLAN routing.
IPv4 Addresses and Subnet Masks
An IPv4 address is a 32-bit logical address, usually written as four decimal octets separated by periods. Each octet represents eight bits and ranges from 0 through 255.
192.168.10.25
11000000.10101000.00001010.00011001A subnet mask is another 32-bit value. Mask bits set to 1 identify the network portion; mask bits set to 0 identify the host portion.
Address: 192.168.10.25 11000000.10101000.00001010.00011001
Mask: 255.255.255.0 11111111.11111111.11111111.00000000
Network: 192.168.10.0 11000000.10101000.00001010.00000000The network address can be found conceptually by performing a bitwise AND between the address and the mask. A 1 AND 1 produces 1; every other combination produces 0.
CIDR prefix length is slash notation showing how many leading bits are network bits. For example, /24 means 24 network bits and 8 host bits.
Common CIDR Prefixes
A longer prefix creates more, smaller subnets. It leaves fewer host bits, so each subnet supports fewer addresses.
| Prefix length | Dotted-decimal mask | Total addresses | Usable hosts in conventional subnetting | Block size in relevant octet |
|---|---|---|---|---|
| /24 | 255.255.255.0 | 256 | 254 | 256 |
| /25 | 255.255.255.128 | 128 | 126 | 128 |
| /26 | 255.255.255.192 | 64 | 62 | 64 |
| /27 | 255.255.255.224 | 32 | 30 | 32 |
| /28 | 255.255.255.240 | 16 | 14 | 16 |
| /29 | 255.255.255.248 | 8 | 6 | 8 |
| /30 | 255.255.255.252 | 4 | 2 | 4 |
| /31 | 255.255.255.254 | 2 | Special point-to-point behavior | 2 |
| /32 | 255.255.255.255 | 1 | Single host or route | 1 |
Borrowing Host Bits
Subnetting extends the network prefix by borrowing bits from the original host portion. If you borrow n bits, the number of equal-size subnets is 2n. The remaining host bits determine the size of each subnet.
| Calculation | Formula | Purpose |
|---|---|---|
| Number of equal subnets | 2borrowed bits | Determines how many subnets are created. |
| Total addresses per subnet | 2remaining host bits | Determines the complete address block size. |
| Usable hosts | 2host bits − 2 | Removes the conventional network and broadcast addresses. |
| Block size | 256 − mask value in the interesting octet | Finds the increment between subnet boundaries. |
The conventional usable-host formula applies to normal multi-host subnets. The first address is the network address and the last is the broadcast address, so neither is normally assigned to an endpoint.
Subnet Increment and Address Ranges
The interesting octet is the mask octet that is neither 255 nor 0. Subnet boundaries increment in that octet. The block size or increment is 256 minus the mask value in that octet.
For 255.255.255.192, the interesting octet is the fourth octet and the block size is 256 − 192 = 64. The subnet boundaries are therefore 0, 64, 128, and 192.
- List the network boundaries by repeatedly adding the block size.
- The network address is the boundary at the beginning of the block.
- The broadcast address is one less than the next boundary.
- The usable range begins one address after the network and ends one address before the broadcast.
Example: Split 192.168.10.0/24 into Four Equal Subnets
Four subnets require 2 borrowed bits because 22 = 4. The original prefix is /24; borrowing two host bits produces /26. The mask is 255.255.255.192, leaving six host bits. Each subnet has 26 = 64 total addresses and 62 conventional usable hosts.
| Subnet number | Network address | Prefix/mask | First usable address | Last usable address | Broadcast address |
|---|---|---|---|---|---|
| 1 | 192.168.10.0 | /26 — 255.255.255.192 | 192.168.10.1 | 192.168.10.62 | 192.168.10.63 |
| 2 | 192.168.10.64 | /26 — 255.255.255.192 | 192.168.10.65 | 192.168.10.126 | 192.168.10.127 |
| 3 | 192.168.10.128 | /26 — 255.255.255.192 | 192.168.10.129 | 192.168.10.190 | 192.168.10.191 |
| 4 | 192.168.10.192 | /26 — 255.255.255.192 | 192.168.10.193 | 192.168.10.254 | 192.168.10.255 |
Choosing a Subnet from a Host Requirement
To support a required number of devices, select the smallest subnet whose usable capacity is large enough. Find the smallest value of h satisfying 2h − 2 ≥ required hosts.
For 50 usable hosts:
/27leaves 5 host bits: 25 − 2 = 30 usable hosts, which is insufficient./26leaves 6 host bits: 26 − 2 = 62 usable hosts, which is sufficient.
Therefore, choose a /26 for a 50-host conventional LAN. The extra capacity can accommodate a gateway, infrastructure addresses, growth, and reservations.
FLSM: Equal-Size Subnets
Fixed Length Subnet Masking (FLSM) uses one prefix length for every subnet created from a parent network. Use FLSM when segments have similar host requirements or when uniformity is more important than maximum address efficiency.
- Identify the parent prefix and the required number of subnets.
- Choose the smallest number of borrowed bits for which 2bits meets the subnet requirement.
- Add those bits to the parent prefix.
- Convert the resulting prefix to a mask.
- Calculate the block size and list every network boundary.
- Record network, usable, and broadcast addresses.
In the /24 example, two borrowed bits produce four /26 subnets. Each has the same mask, capacity, and address structure.
VLSM: Subnets Based on Different Requirements
Variable Length Subnet Masking (VLSM) allows different prefix lengths within one parent network. This avoids wasting large blocks on small links or departments.
Always allocate the largest requirement first. For each requirement, select the smallest block that provides the needed usable hosts, then begin the next allocation at the next available aligned boundary.
VLSM Example
Use 192.168.50.0/24 for LAN requirements of 100, 50, 20, and 10 hosts, plus a point-to-point router link. The LAN gateway is reserved as the first usable address in each LAN.
| Segment | Required hosts | Chosen prefix | Subnet mask | Network address | Usable host range | Broadcast address | Gateway/reserved address |
|---|---|---|---|---|---|---|---|
| Department A | 100 | /25 | 255.255.255.128 | 192.168.50.0 | 192.168.50.1–192.168.50.126 | 192.168.50.127 | 192.168.50.1 gateway |
| Department B | 50 | /26 | 255.255.255.192 | 192.168.50.128 | 192.168.50.129–192.168.50.190 | 192.168.50.191 | 192.168.50.129 gateway |
| Department C | 20 | /27 | 255.255.255.224 | 192.168.50.192 | 192.168.50.193–192.168.50.222 | 192.168.50.223 | 192.168.50.193 gateway |
| Department D | 10 | /28 | 255.255.255.240 | 192.168.50.224 | 192.168.50.225–192.168.50.238 | 192.168.50.239 | 192.168.50.225 gateway |
| Router link | 2 endpoints | /30 | 255.255.255.252 | 192.168.50.240 | 192.168.50.241–192.168.50.242 | 192.168.50.243 | Reserve .241 and .242 for routers |
Addresses 192.168.50.244–192.168.50.255 remain unused and can be documented for future growth. The blocks do not overlap because each allocation begins after the preceding block's broadcast address.
Find Subnet Details from an IP Address
Given 172.16.35.77/27, first convert the prefix: /27 = 255.255.255.224. The interesting octet is the fourth octet, and the block size is 256 − 224 = 32.
- List boundaries: 0, 32, 64, 96, 128, 160, 192, and 224.
- The value 77 falls between 64 and 95, so the host is in the subnet beginning at 64.
- Network address:
172.16.35.64. - Broadcast address:
172.16.35.95, one less than the next boundary, 96. - Usable range:
172.16.35.65–172.16.35.94. - If numbering from zero, this is subnet number 2 within the
172.16.35.0/24parent. If numbering from one, it is subnet 3. State the convention used.
Binary AND validates the result: applying the mask keeps the first 27 bits and clears the final five host bits, producing 172.16.35.64.
Special Prefixes: /31 and /32
A /31 contains two addresses and is commonly used for point-to-point links under RFC 3021. In that context, both addresses can represent the two link endpoints, so the traditional assumption that one address is a network address and the other is a broadcast address does not apply in the usual way. Use /31 only when the devices and deployment support this behavior.
A /32 identifies one IPv4 address. It is used for a single-host route, loopback address, or host-specific route. It is not a conventional multi-host subnet.
Assigning Router Interfaces
A default gateway must be a usable address in the same subnet as its hosts. For two /26 LANs, 10.1.1.0/26 has usable addresses .1–.62, and 10.1.1.64/26 has usable addresses .65–.126.
enable
configure terminal
interface gigabitEthernet0/0
ip address 10.1.1.1 255.255.255.192
no shutdown
interface gigabitEthernet0/1
ip address 10.1.1.65 255.255.255.192
no shutdown
endDo not assign 10.1.1.0, 10.1.1.63, 10.1.1.64, or 10.1.1.127 to ordinary hosts. These are network or broadcast addresses for the two /26 subnets.
Verification and Documentation
A useful subnet plan records the segment name, VLAN association, prefix, mask, network address, broadcast address, gateway, DHCP range, reserved addresses, and purpose.
show ip interface brief
show running-config | section interface
show ip route
show interfacesUse these Cisco IOS commands to check interface addresses, administrative and operational state, configured masks, connected routes, errors, and link details. On endpoints, inspect local addressing and routes with:
ipconfig /all
ip addr show
ip route
ping <destination-ip>Check that every configured address belongs to the intended subnet, every gateway is usable, DHCP ranges exclude gateways and reservations, and VLAN-to-subnet associations are documented. Compare network and broadcast boundaries to detect overlapping blocks before deployment.
Troubleshooting Subnetting Errors
Hosts in the Same LAN Cannot Communicate
- Compare the IP address and mask on each host.
- Calculate each host's network address; a neighboring subnet may have been assigned accidentally.
- Verify that the interface and switch port are up and that the port belongs to the correct VLAN.
- Check ARP information and duplicate-address alerts.
A Host Cannot Reach Outside Its Subnet
- Confirm that the default gateway is a usable address in the host's subnet.
- Ping the gateway first.
- Use
show ip interface briefto check the router interface. - Use
show ip routeto confirm a route toward the destination network.
Subnet Ranges Overlap
- Recalculate the block size from the mask's interesting octet.
- List every network and broadcast boundary.
- Allocate VLSM blocks from largest to smallest and start each block at a valid aligned boundary.
- Compare the address plan with the masks configured on devices.
A Network or Broadcast Address Was Assigned to a Device
- Calculate the first and last address of the conventional subnet.
- Assign hosts only between those boundaries.
- Confirm whether the link is genuinely a supported /31 point-to-point deployment before using both addresses.
Subnetting Checklist
- Write the parent network and prefix.
- Determine whether the design needs equal-size FLSM or mixed-size VLSM.
- For FLSM, borrow enough bits to meet the subnet count.
- For host requirements, leave enough host bits for usable capacity.
- Convert the prefix to a dotted-decimal mask.
- Find the interesting octet and block size.
- List network, usable, and broadcast ranges.
- Check alignment and overlaps.
- Reserve gateways, DHCP exclusions, infrastructure addresses, and growth space.
- Verify interfaces, VLAN associations, connected routes, and end-to-end reachability.
For routing context, review OSPF configuration and the OSI reference model.