Course contents

Chapter 2: IP Subnetting and VLSMLesson 1 of 8

Subnetting

Subnet masks, CIDR, network and broadcast addresses, usable host counts, and VLSM: the math behind every subnet calculator.

Intermediate · 8 min read · Before this: IP Addressing

Technical definition

Subnetting is the process of dividing an IP network into smaller networks, called subnets, by borrowing bits from the host portion of the address and using them as network bits. The subnet mask or CIDR prefix length shows where the network part ends and the host part begins.

Subnetting means taking one larger network and dividing it into smaller, self-contained networks called subnets. Say a company has a single block of address space, like 192.168.1.0/24. It can split that block up to give separate ranges to different departments, floors, or VLANs, instead of putting every device on one flat network.

The guided series

This page is the overview. To learn to subnet by hand, work through these short lessons in order. Each one has worked answers to check yourself against and ends with the practice drill.

  1. Subnet masks and CIDR: Read a mask in binary, convert between /prefix and dotted mask, count hosts.
  2. A step-by-step method: Five steps that find the network, broadcast and host range of any address.
  3. Worked examples: /24, /25, /26: The method on the prefixes you meet most, one step at a time.
  4. Harder examples: /20 and /27: When the interesting octet is the third, and when blocks get small.
  5. Network, broadcast and usable hosts: Is this address usable? Same subnet? Which prefix fits 500 hosts?
  6. VLSM for a real office: Plan a whole office from one /23: users, phones, guests, servers and links.
  7. Find the mistake: Spot the error in someone else's answer, the way a reviewer would.

Why subnet at all?

  • Smaller broadcast domains. Every device on the same subnet shares broadcast traffic (ARP requests, DHCP discovery, and so on). Fewer devices per subnet means less broadcast noise and better performance.
  • Isolation and security. Traffic between subnets has to pass through a router. This gives you a natural point to apply access control, like keeping a guest Wi-Fi subnet from reaching internal servers. Subnetting alone doesn't isolate anything: a router forwards between its subnets by default, so the isolation comes from the ACLs or firewall policies you add there.
  • Efficient use of address space. Instead of wasting a large block of addresses on a department with only 10 devices, subnetting lets you size each network to roughly match what it actually needs.

Think of one big open-plan office divided into separate rooms. Everyone can still reach everyone else through the hallway (the router), but noise and traffic inside one room no longer spill into every other room.

The subnet mask and prefix length

A subnet mask marks which bits of an IPv4 address are the network portion and which are the host portion. A 1 marks a network bit, a 0 marks a host bit. 255.255.255.0 in binary is 24 ones followed by 8 zeros. That's why it's also written as the CIDR prefix /24: the number after the slash simply counts the leading 1 bits.

PrefixSubnet maskHost bitsUsable hosts
/24255.255.255.08254
/25255.255.255.1287126
/26255.255.255.192662
/27255.255.255.224530
/28255.255.255.240414
/29255.255.255.24836
/30255.255.255.25222

That last column follows 2ⁿ − 2, where n is the number of host bits. You subtract 2 for the reserved network and broadcast addresses on every subnet up to /30 (/31 and /32 are exceptions). The CIDR Calculator converts between prefix and mask instantly. The Wildcard Mask Calculator shows the inverted form of a mask, used in access lists and OSPF configuration.

On real equipment you will meet both forms. Routing tables and most modern configs show the prefix length, while Cisco's ip address command still takes the dotted mask.

Splitting one network into equal subnets

The core move in subnetting is borrowing host bits to create more network bits. Take 192.168.1.0/24 and borrow 2 bits from the host portion to make it a /26. Those 2 borrowed bits give 2² = 4 equal-sized subnets, each with 2⁶ − 2 = 62 usable hosts:

SubnetNetwork addressUsable rangeBroadcast
1192.168.1.0/26.1 – .62192.168.1.63
2192.168.1.64/26.65 – .126192.168.1.127
3192.168.1.128/26.129 – .190192.168.1.191
4192.168.1.192/26.193 – .254192.168.1.255

Enter 192.168.1.0/26 into the Subnet Calculator. It will show you the full breakdown: network address, broadcast address, and usable host range, for any address and prefix you give it.

Borrow bits and watch the /24 split

Use the controls below to borrow more or fewer bits from 192.168.1.0/24 and watch it split into equal subnets in real time.

Borrow 2 host bits from 192.168.1.0/24 to create 4 subnets of /26 each.

2
192.168.1.0 – 63
192.168.1.64 – 127
192.168.1.128 – 191
192.168.1.192 – 255
Each coloured block is an IPv4 subnet, not a device or connection. The list gives its full address range, including the network and broadcast addresses; these ranges are not lists of usable hosts.

HR, Finance and IT sharing one /24

A small office needs three separate networks: HR, Finance, and IT. Each gets its own subnet, so traffic between them passes through the router, where rules can control it, and they all share one 192.168.1.0/24 block:

Diagram
Path, step by step
HR
192.168.1.0/26
Finance
192.168.1.64/26
IT
192.168.1.128/26
Router
Routes between all three

Read in arrow direction. Labels describe each stage or hop; connectors show the sequence, not a complete physical cabling plan or time to scale.

One /24 block split into three department subnets, all reachable through the same router.

Devices within HR can talk to each other directly, without a router. If Finance needs to reach a file server on the IT subnet, that traffic has to pass through the router. That's exactly where a network administrator would apply a rule to allow or block it.

VLSM: subnets of different sizes

Splitting into equal subnets is simple, but it wastes space when departments need very different numbers of hosts. VLSM (Variable Length Subnet Masking) solves this by giving each subnet only as many host bits as it actually needs. The standard approach: sort requirements largest-first. Then allocate each one starting from the next free address, sized to the smallest power of two that fits.

For example, start from 192.168.1.0/24 with three requirements: Sales needs 50 hosts, Engineering needs 25, and Guest Wi-Fi needs 10:

DepartmentHosts neededAllocated blockUsable hosts
Sales50192.168.1.0/2662
Engineering25192.168.1.64/2730
Guest Wi-Fi10192.168.1.96/2814

Each block is sized to its actual need, instead of every department getting an identical, mostly-empty /26. You don't need to do this by hand. The VLSM Calculator takes a base network and a list of named requirements, and produces exactly this kind of allocation table.

Doing it in your head: the block size

  • Number of subnets = 2 raised to the number of bits you borrow.
  • Block size is the gap between each subnet's network address. It equals 256 minus the first octet of the subnet mask that is not 255. For a /26 mask (255.255.255.192), that's 256 − 192 = 64. That's exactly the spacing in the four-subnet table above (.0, .64, .128, .192).

FAQ

Why not just put every device on one giant network?
You could, but every device would share the same broadcast domain. That means ARP requests, DHCP discovery, and other broadcast traffic from any one device reaches every other device. On a large network, that creates real, measurable performance problems. It also removes the natural boundary a router provides, where security rules can be applied. Subnetting fixes the first problem and creates that boundary; the rules themselves (ACLs or firewall policies) still have to be configured.
Why do I subtract 2 from the usable host count?
Every subnet up to /30 reserves its first address as the network address, which identifies the subnet itself. It also reserves its last address as the broadcast address, which reaches every device on the subnet. Neither address can be assigned to a device. That's why usable hosts is 2ⁿ − 2, not 2ⁿ.
When should I use VLSM instead of equal-size subnets?
Use it whenever your subnets need meaningfully different numbers of hosts. Equal subnetting is simpler to plan, but it wastes address space on smaller subnets. VLSM sizes each subnet to what it actually needs. This matters more as address space gets scarcer or the network grows.