Fundamentals

Subnetting Made Simple: A Step-by-Step Guide to IPv4 and CIDR

Subnetting looks intimidating until you see the pattern behind it. This guide walks you through IPv4 and CIDR step by step, with the block size method, fully worked examples, VLSM design, route summarization and a handy /24 to /30 reference table.

Subnetting has a reputation as the part of networking that separates people who “get it” from people who do not. The truth is less dramatic. Subnetting is a small set of rules applied consistently, and once you see the pattern behind them you can solve most problems in your head in seconds. This guide takes you from IPv4 basics to CIDR, the block size method, fully worked examples, VLSM design and route summarization, with a reference table you can keep next to your keyboard.

Why subnetting still matters

It is tempting to think a calculator makes subnetting knowledge unnecessary. In practice, you use subnetting constantly, often without noticing. Every time you size a DHCP scope, write an access list, choose an address for a new VLAN interface, read a routing table or troubleshoot why two hosts cannot reach each other, you are applying subnetting logic.

Fluent subnetting gives you three practical advantages:

  • Faster troubleshooting. You can spot a wrong mask or a gateway outside the host’s subnet at a glance.
  • Better design. You can build addressing plans that are efficient, easy to summarize and easy to understand.
  • Exam and interview confidence. Subnetting appears in nearly every networking certification and technical interview, and it is usually timed.

Calculators are great for checking your work, and we have one on our network tools page. But the goal of this guide is to make you independent of them.

IPv4 address basics in five minutes

An IPv4 address is a 32-bit number. For human convenience, we split it into four 8-bit groups called octets and write each as a decimal number from 0 to 255, separated by dots. The address 192.168.10.25 is really this binary value:

Octet Decimal Binary
1st 192 11000000
2nd 168 10101000
3rd 10 00001010
4th 25 00011001

Each bit position in an octet has a fixed value. From left to right they are 128, 64, 32, 16, 8, 4, 2 and 1. To convert binary to decimal, add the values of the bits that are set to 1. For 00011001, that is 16 + 8 + 1 = 25. Memorize those eight values; everything else in subnetting builds on them.

Network portion and host portion

Every IPv4 address is divided into two parts. The network portion identifies which subnet the address belongs to, and the host portion identifies the individual interface within that subnet. The subnet mask tells you where the dividing line sits.

A subnet mask is also 32 bits long. It is a continuous run of 1s followed by a continuous run of 0s. The 1s mark the network bits and the 0s mark the host bits. The mask 255.255.255.0 is 24 ones followed by 8 zeros, so the first three octets are the network and the last octet is the host portion.

Network, broadcast and usable hosts

Within any traditional subnet, two addresses are special:

  • The network address has all host bits set to 0. It identifies the subnet itself.
  • The broadcast address has all host bits set to 1. Packets sent to it reach every host in the subnet.

Everything in between is usable for hosts. That gives us the two formulas you will use constantly:

  • Total addresses in a subnet = 2h, where h is the number of host bits.
  • Usable hosts = 2h − 2.

When you borrow bits from the host portion to create subnets, the number of subnets you get is 2s, where s is the number of borrowed bits.

CIDR notation and private address space

Originally, IPv4 used fixed classes. Class A networks had an 8-bit network portion, Class B had 16 bits and Class C had 24 bits. That was simple but wasteful: an organization needing 300 addresses was too big for a Class C and wasted most of a Class B.

Classless Inter-Domain Routing (CIDR), introduced in RFC 1519 and updated by RFC 4632, removed the fixed boundaries. A network can now have any prefix length from /0 to /32. CIDR notation writes the prefix length after a slash, counting the 1 bits in the mask. These two forms mean exactly the same thing:

  • 192.168.10.0 with mask 255.255.255.192
  • 192.168.10.0/26

Because 255.255.255.192 contains 26 leading ones (8 + 8 + 8 + 2), the prefix is /26. You will see both forms in the real world. Cisco IOS interface configuration uses dotted-decimal masks, while routing tables, documentation and most other platforms favor CIDR.

Address ranges you should recognize

Range Purpose Reference
10.0.0.0/8 Private addressing RFC 1918
172.16.0.0/12 Private addressing (172.16.0.0 to 172.31.255.255) RFC 1918
192.168.0.0/16 Private addressing RFC 1918
100.64.0.0/10 Shared address space for carrier-grade NAT RFC 6598
169.254.0.0/16 Link-local (automatic addressing when DHCP fails) RFC 3927
127.0.0.0/8 Loopback RFC 1122
Pro tip: If a Windows or macOS client shows a 169.254.x.x address, it did not receive a DHCP lease. Check the switch port VLAN, the DHCP relay (ip helper-address) and the DHCP server’s scope before anything else.

Subnet reference table: /24 to /30

Most day-to-day subnetting in enterprise networks happens in the last octet. This table covers the prefixes you will meet most often. The wildcard mask column is useful for ACLs and OSPF network statements; it is simply the subnet mask inverted.

Prefix Subnet mask Wildcard mask Block size Total addresses Usable hosts Subnets per /24
/24 255.255.255.0 0.0.0.255 256 256 254 1
/25 255.255.255.128 0.0.0.127 128 128 126 2
/26 255.255.255.192 0.0.0.63 64 64 62 4
/27 255.255.255.224 0.0.0.31 32 32 30 8
/28 255.255.255.240 0.0.0.15 16 16 14 16
/29 255.255.255.248 0.0.0.7 8 8 6 32
/30 255.255.255.252 0.0.0.3 4 4 2 64

Two more prefixes are worth knowing. A /31 contains two addresses and, under RFC 3021, both can be used on point-to-point links because a broadcast address is not needed there. A /32 identifies a single host and is commonly used for loopback interfaces and host routes.

Note: The same patterns repeat in every octet. A /16 mask is 255.255.0.0, and /20 is 255.255.240.0, with a block size of 16 in the third octet, exactly like /28 in the fourth octet.

The block size method: subnetting without binary

Binary is the foundation, but you do not want to convert every address to ones and zeros under exam pressure. The block size method, sometimes called the “magic number” method, gets you the answer with simple arithmetic.

  1. Find the interesting octet. This is the octet where the subnet mask is neither 255 nor 0. For /26 (255.255.255.192) it is the fourth octet. For /20 (255.255.240.0) it is the third.
  2. Calculate the block size. Subtract the mask value in the interesting octet from 256. For /26 that is 256 − 192 = 64.
  3. List the multiples. Subnets start at 0 and increase by the block size: 0, 64, 128, 192.
  4. Find the network. The network address is the multiple equal to or just below the address’s value in the interesting octet.
  5. Find the broadcast. The broadcast is the next multiple minus 1.
  6. Find the host range. First usable is network + 1; last usable is broadcast − 1.

Octets to the left of the interesting octet are copied unchanged. Octets to the right are 0 in the network address and 255 in the broadcast address. That one rule handles every prefix length.

Worked examples, step by step

Work through these with a pen before reading the answers. Repetition is what makes subnetting fast.

Example 1: Split 192.168.10.0/24 into four equal subnets

You need four subnets. Because 22 = 4, you borrow 2 host bits, turning /24 into /26. The mask is 255.255.255.192, the block size is 64, and each subnet has 26 − 2 = 62 usable hosts.

Subnet Network First usable Last usable 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

Example 2: Which subnet does 192.168.1.130/26 belong to? (binary method)

To see what the block size method is really doing, solve this one in binary. A router finds the network address by performing a bitwise AND between the address and the mask: a result bit is 1 only if both input bits are 1. Only the fourth octet is interesting here.

Value Decimal Binary (4th octet)
Address 130 10000010
Mask 192 11000000
AND result 128 10000000

The network is 192.168.1.128/26. Setting the six host bits to 1 gives 10111111, which is 191, so the broadcast is 192.168.1.191. The usable range is 192.168.1.129 to 192.168.1.190. Check it with the block size method: multiples of 64 are 0, 64, 128 and 192, and 130 falls between 128 and 191. Same answer, much faster.

Example 3: Find the network for 172.16.45.200/20

This one catches people because the interesting octet is not the last one.

  1. A /20 mask is 255.255.240.0, so the interesting octet is the third.
  2. Block size is 256 − 240 = 16.
  3. Multiples of 16 in the third octet: 0, 16, 32, 48, 64 and so on.
  4. The third octet of the address is 45, which falls between 32 and 47. The network starts at 32.
  5. The fourth octet is to the right of the interesting octet, so it is 0 for the network and 255 for the broadcast.

Result: network 172.16.32.0/20, broadcast 172.16.47.255, usable hosts 172.16.32.1 to 172.16.47.254. With 12 host bits, the subnet holds 212 − 2 = 4,094 usable hosts. Notice that addresses such as 172.16.40.0 and 172.16.39.255 are perfectly valid host addresses inside this subnet; only the very first and very last addresses are reserved.

Example 4: Size a subnet for 500 hosts

Here you work backward from a requirement. Find the smallest number of host bits where 2h − 2 is at least 500.

  • 8 host bits: 256 − 2 = 254. Too small.
  • 9 host bits: 512 − 2 = 510. Big enough.

Nine host bits leaves 32 − 9 = 23 network bits, so you need a /23 with mask 255.255.254.0. If you allocate 10.20.0.0/23, the subnet runs from 10.20.0.0 to 10.20.1.255, with usable hosts from 10.20.0.1 to 10.20.1.254. A /23 must start on an even third octet, because the block size in that octet is 2.

Check your answers with Python

Python’s built-in ipaddress module is a handy way to verify practice problems or generate address plans. This short script reproduces the examples above.

import ipaddress

# Example 1: split a /24 into four /26 subnets
for subnet in ipaddress.ip_network("192.168.10.0/24").subnets(new_prefix=26):
    hosts = list(subnet.hosts())
    print(subnet, hosts[0], hosts[-1], subnet.broadcast_address)

# Examples 2 and 3: find the network an address belongs to
print(ipaddress.ip_interface("192.168.1.130/26").network)   # 192.168.1.128/26
print(ipaddress.ip_interface("172.16.45.200/20").network)   # 172.16.32.0/20

# Example 4: broadcast of a /23
print(ipaddress.ip_network("10.20.0.0/23").broadcast_address)  # 10.20.1.255

VLSM: sizing subnets to real needs

Splitting a network into equal pieces is easy, but real networks rarely need equal pieces. A user VLAN may need 100 addresses while a router-to-router link needs two. Variable Length Subnet Masking (VLSM) lets you use different prefix lengths inside one block so nothing is wasted.

The golden rule of VLSM is simple: allocate the largest subnets first. Doing so keeps every subnet aligned on a valid boundary for its size and prevents overlaps.

VLSM example: carve up 10.10.0.0/24

You have been given 10.10.0.0/24 for a small site with these requirements:

  • Staff VLAN: 100 hosts
  • Engineering VLAN: 50 hosts
  • Management VLAN: 20 hosts
  • Two point-to-point router links: 2 hosts each

Pick the smallest prefix that fits each requirement, then allocate from largest to smallest:

Requirement Prefix Subnet Usable range Broadcast
Staff (100) /25 (126 hosts) 10.10.0.0/25 10.10.0.1 – 10.10.0.126 10.10.0.127
Engineering (50) /26 (62 hosts) 10.10.0.128/26 10.10.0.129 – 10.10.0.190 10.10.0.191
Management (20) /27 (30 hosts) 10.10.0.192/27 10.10.0.193 – 10.10.0.222 10.10.0.223
Link A (2) /30 (2 hosts) 10.10.0.224/30 10.10.0.225 – 10.10.0.226 10.10.0.227
Link B (2) /30 (2 hosts) 10.10.0.228/30 10.10.0.229 – 10.10.0.230 10.10.0.231

The remaining space, 10.10.0.232 to 10.10.0.255, is still free and can be used as a /29 (10.10.0.232/29) and a /28 (10.10.0.240/28) for future needs. Applying one of these subnets on a Cisco router interface looks like this:

interface GigabitEthernet0/0/1
 description Link A to BRANCH-RTR
 ip address 10.10.0.225 255.255.255.252
 no shutdown
Watch out: Allocating small subnets first is the classic VLSM mistake. If you placed the /30 links at 10.10.0.0 and 10.10.0.4, you could no longer fit a /25 at the start of the block, because a /25 must begin at .0 or .128.

Route summarization (supernetting)

Summarization is subnetting in reverse. Instead of splitting a block into smaller pieces, you combine several contiguous networks into one shorter prefix. Summaries shrink routing tables, reduce the impact of individual link flaps and make ACLs and firewall policies easier to read. They are a core design technique in protocols such as OSPF, where summarization happens at area boundaries.

How to find a summary

  1. Write the networks in binary, at least the octet where they differ.
  2. Count the number of leading bits they share.
  3. The summary is the first network with a prefix length equal to the shared bits.

Take 192.168.0.0/24 through 192.168.3.0/24. The third octets are 0, 1, 2 and 3, which in binary are 00000000, 00000001, 00000010 and 00000011. The first six bits are identical, so the summary keeps 16 + 6 = 22 bits: 192.168.0.0/22.

Similarly, 172.16.8.0/24 through 172.16.15.0/24 share the bits 00001 in the third octet (8 is 00001000 and 15 is 00001111), so they summarize to 172.16.8.0/21.

Note: A clean summary requires the networks to be contiguous and aligned to the summary’s boundary. The networks 172.16.6.0/24 through 172.16.9.0/24 cross the boundary at 172.16.8.0, so the smallest single prefix covering all four is 172.16.0.0/20, which also claims twelve networks you do not own. In that case you would advertise two summaries (172.16.6.0/23 and 172.16.8.0/23) instead.

This is why good addressing plans assign contiguous, aligned blocks to each site or function from the start. If you document your allocations as you go, which our network documentation guide covers in detail, summarization becomes almost automatic.

Common subnetting mistakes and how to avoid them

  • Forgetting the minus 2. A /27 has 32 addresses but only 30 usable hosts. Size DHCP scopes and VLANs on usable hosts.
  • Using the wrong interesting octet. For prefixes between /17 and /23, the action is in the third octet. Always identify the octet before you start counting.
  • Treating x.x.x.0 or x.x.x.255 as always invalid. In larger subnets such as a /23 or /20, many addresses ending in .0 or .255 are ordinary host addresses.
  • Misaligned subnets. A /26 cannot start at .32. Network addresses must be multiples of the block size.
  • Overlapping allocations. Two subnets that overlap cause intermittent, confusing reachability problems. Track every allocation in a spreadsheet or IPAM tool.
  • Gateway outside the subnet. If a host’s default gateway is not inside its own subnet, it cannot ARP for it, and off-subnet traffic fails.

Once you are comfortable with IPv4, apply the same thinking to IPv6. The address is longer, but prefix logic is the same, and standard /64 subnets make many decisions simpler. Our IPv6 guide for network admins is a natural next step, and subnetting practice fits neatly into week two of our 90-day CCNA study plan.

Key takeaways

  • An IPv4 address is 32 bits; the mask or CIDR prefix tells you which bits are network and which are host.
  • Total addresses equal 2h and usable hosts equal 2h − 2, except on /31 point-to-point links (RFC 3021).
  • The block size method (256 minus the mask value in the interesting octet) lets you find network, broadcast and host range without binary.
  • Network addresses are always multiples of the block size in the interesting octet.
  • With VLSM, size each subnet to its real needs and allocate the largest subnets first.
  • Summarization combines contiguous, aligned networks into one shorter prefix and depends on a well-planned addressing scheme.
  • Practice daily for a couple of weeks and subnetting becomes automatic.

Practice is what turns these rules into instinct, so try a handful of problems every day and check your answers with our subnet calculator. If your organization’s addressing has grown messy over the years, with overlapping ranges, undocumented subnets or no room to summarize, our Network Health Assessment can map what you have and propose a clean plan.

Frequently asked questions

Why do we subtract 2 when calculating usable hosts?

In a traditional IPv4 subnet, the first address (all host bits set to 0) identifies the network itself and the last address (all host bits set to 1) is the directed broadcast address. Neither can be assigned to a host, so usable hosts equal 2 to the power of the host bits, minus 2. The exception is a /31 point-to-point link defined in RFC 3021, where both addresses are usable.

What is the difference between a subnet mask and CIDR notation?

They express the same information in different formats. A subnet mask such as 255.255.255.192 is written in dotted decimal, while CIDR notation such as /26 simply counts the number of leading 1 bits in that mask. 255.255.255.192 has 26 leading ones, so it is /26.

What is the fastest way to subnet in my head?

Use the block size method. Find the interesting octet (the one where the mask is neither 255 nor 0), subtract the mask value in that octet from 256 to get the block size, and count up in multiples of the block size. The multiple at or just below your address is the network, and the next multiple minus one is the broadcast.

What is VLSM and why is it used?

Variable Length Subnet Masking means using different prefix lengths within the same address block, so each subnet is sized to its actual needs. It avoids wasting addresses, for example by using a /30 or /31 for a point-to-point link instead of a /24. Always allocate the largest subnets first to keep boundaries aligned.

Which IPv4 address ranges are private?

RFC 1918 defines three private ranges: 10.0.0.0/8, 172.16.0.0/12 (172.16.0.0 to 172.31.255.255) and 192.168.0.0/16. These addresses are not routed on the public internet and are normally translated with NAT when hosts need internet access.

Keep learning

Related guides


Ready when you are

Let’s make your network faster, safer and easier to run

Tell us what you are working on — a messy rack, a flat network, an upcoming CCNA exam — and we will suggest the simplest next step.