← Learn networking

Subnetting Explained: CIDR, Masks and Host Counts

6 min read

Subnetting is the single most-tested skill in the CCNA, and it is also one of the most useful things a working network engineer does. The idea is simple: take one block of IP addresses and divide it into smaller, right-sized blocks — subnets — so that each network segment gets the addresses it needs and none it doesn't. This article explains the notation, the maths, and a reliable method for working out any subnet by hand.

In simple words

Think of one big office floor. If you leave it as one open hall, everyone shouts across everyone else. So you build cabins: each team gets its own room, and each room has its own set of desk numbers. Subnetting is exactly that — one big block of IP addresses divided into smaller rooms (subnets), each with its own set of usable numbers.

What an IPv4 address really is

An IPv4 address is 32 bits, usually written as four decimal numbers (octets) separated by dots, for example 192.168.20.77. The address is split into two parts: a network part that identifies the subnet, and a host part that identifies the device on that subnet. Where the split falls is defined by the prefix length — the /26 in 192.168.20.0/26 — and everything in subnetting follows from that number.

Reading CIDR notation

CIDR (Classless Inter-Domain Routing) notation writes the network address followed by a slash and the number of bits in the network part. A /26 means the first 26 bits are the network part and the remaining 6 bits are the host part. The most common prefixes you will meet:

  • /8 — 24 host bits — 16,777,216 addresses
  • /16 — 16 host bits — 65,536 addresses
  • /24 — 8 host bits — 256 addresses
  • /25 — 7 host bits — 128 addresses
  • /26 — 6 host bits — 64 addresses
  • /27 — 5 host bits — 32 addresses
  • /28 — 4 host bits — 16 addresses
  • /29 — 3 host bits — 8 addresses
  • /30 — 2 host bits — 4 addresses (point-to-point links)

The address count for a prefix is always 2 raised to the number of host bits. For /26, that is 2^6 = 64.

Subnet masks in binary and dotted decimal

The subnet mask is just the prefix length written as 32 bits: network bits are 1s, host bits are 0s. For /26, the mask is 26 ones followed by 6 zeros. The last octet is 11000000 in binary, which is 192 in decimal — so the mask is 255.255.255.192. A quick way to get the interesting octet: subtract the mask value from 256 (the "magic number"). For /26, 256 − 192 = 64, so subnets fall on boundaries of 64 in the last octet: .0, .64, .128, .192.

Host counts and the minus-two rule

Out of the 2^host-bits addresses, two are reserved and cannot be assigned to devices: the network address (all host bits zero — the first address, which names the subnet) and the broadcast address (all host bits one — the last address, used to reach every host). So a /26 gives 64 − 2 = 62 usable host addresses. The main exceptions: /31 prefixes (RFC 3021) use both addresses for point-to-point links, and /32 is a single host route.

Worked example: 192.168.20.77/26

A device has the address 192.168.20.77 with prefix length /26. Work out its subnet:

  1. Host bits = 32 − 26 = 6. Addresses per subnet = 2^6 = 64. Usable = 62.
  2. Mask: last octet 192 → 255.255.255.192. Magic number: 256 − 192 = 64.
  3. Subnet boundaries in the last octet: 0, 64, 128, 192. The address 77 falls in the 64–127 block, so the subnet is 192.168.20.64/26.
  4. Network address: 192.168.20.64. Broadcast: 192.168.20.127. Usable range: 192.168.20.65 to 192.168.20.126.
Worked example: where does 192.168.20.77/26 live?
1/6
192.168.20.0/24.0/26.64/26.128/26.192/26block size 64 (magic number)

192.168.20.0/24 divided into four /26 blocks: .0, .64, .128, .192.

  1. 192.168.20.0/24 divided into four /26 blocks: .0, .64, .128, .192.
  2. The address 192.168.20.77 travels across the blocks…
  3. …and lands inside the .64 block.
  4. Network: 192.168.20.64
  5. Broadcast: 192.168.20.127
  6. Usable: .65 – .126 (62 hosts)

Borrowing bits: subnetting a subnet

So far we have split a block using a longer prefix, but where do the extra bits come from? They are borrowed from the host part. Take 10.0.0.0/16 and divide it into /24s: the prefix grows from 16 to 24, so 8 bits are borrowed, producing 2^8 = 256 subnets (10.0.0.0/24 through 10.0.255.0/24), each with 254 usable hosts. The general rule: number of subnets = 2^(new prefix length − original prefix length). Borrowing 2 bits from a /24 to make /26s gives 2^2 = 4 subnets of 62 usable hosts each (.0/26, .64/26, .128/26, .192/26). Working the other direction is just as useful: if you need at least 6 subnets from a /24, you must borrow 3 bits (2^3 = 8 ≥ 6), giving /27s — borrowing only 2 bits yields 4 subnets, which isn't enough. This is the calculation behind every "how many subnets do I get?" exam question.

Quick reference: the prefixes you'll use most

PrefixSubnet maskAddressesUsable hosts
/24255.255.255.0256254
/25255.255.255.128128126
/26255.255.255.1926462
/27255.255.255.2243230
/28255.255.255.2401614
/29255.255.255.24886
/30255.255.255.25242

Learn this table and you can answer most subnetting questions without touching binary: the pattern is simply halving as the prefix grows by one. For anything outside the table — /20, /23, /31 — fall back to the magic-number method from the worked example above.

Common mistakes

  • Forgetting the minus two. A /26 is 62 usable hosts, not 64 — a classic exam trap and a real-world addressing error.
  • Using the network or broadcast address on a host. The first and last addresses of a subnet are not assignable (except on /31 links).
  • Overlapping subnets. 192.168.20.0/25 (addresses .0–.127) and 192.168.20.64/26 (.64–.127) overlap — the second sits inside the first. Always check that new subnets fit inside unused space.

At a glance: why, where, when, how

  • Why: to keep networks organised, reduce noise (broadcast traffic), and use addresses without wasting them.
  • Where: every office LAN, every cloud VPC, every home network split into "main" and "guest".
  • When: whenever one network grows too big, or different groups (staff, guests, servers, cameras) should be separated.
  • How: choose a prefix length (like /26); the mask splits the address into a network part and a host part, as this article explains.

Advantages and disadvantages

Advantages

  • Less noise: a broadcast in one subnet does not disturb the others.
  • Better security: guests can be kept away from servers by design.
  • Easier troubleshooting: an address tells you which part of the network a device belongs to.

Disadvantages

  • Two addresses per subnet are always reserved (network and broadcast), so tiny subnets waste proportionally more.
  • A wrong mask on one device quietly breaks its connectivity — subnetting errors are a classic outage cause.
  • Plans need care: badly sized subnets force renumbering later.

Real-life example

A school has 200 computers. Instead of one giant network, the IT team makes four subnets: classrooms, teachers, office, and the computer lab. When a student computer gets a virus, it can only shout inside the classroom subnet — the office machines never hear it, and the problem is contained in minutes.

FAQ

Why do we still subnet by hand when tools exist?

Because exams test it, interviews test it, and troubleshooting at 2 a.m. often means reasoning about masks without a calculator to hand. The tool checks your work; understanding does the thinking.

What is the difference between a subnet mask and a wildcard mask?

A subnet mask marks network bits with 1s; a wildcard mask (used in ACLs and OSPF network statements) is its inverse, marking host bits with 1s. For 255.255.255.192 the wildcard is 0.0.0.63.

Can a subnet start at any address?

No — subnet boundaries must align to multiples of the block size. A /26 can start at .0, .64, .128 or .192 of an octet, never at .32.

Related: IPv4 Calculator