Course contents · Lesson 11 of 22

CIDR and Subnets Explained Without the Headache

Networks for Engineers · Lesson 11 of 22 · 10 min Engineer

You are creating a cloud network, and the setup form asks for an address range such as 10.0.0.0/16. Later a teammate wants "a /24 for the database", and a tool warns that two ranges overlap. This lesson explains CIDR and subnets: what the slash means, how many addresses you get, and how to split a range into pieces.

An address has a network part and a host part

In lesson 2, a flat number stood for a port. Here you zoom out: each whole IP address is one flat.

As lesson 2 showed, an IPv4 address is 32 bits (a bit is a single 0 or 1): four numbers from 0 to 255, 8 bits each. To see where a block ends, read them in binary, writing numbers with only 0 and 1.

Each of the 8 positions has a value: 128, 64, 32, 16, 8, 4, 2 and 1, from left to right. A 1 means "add this value". So 10 is 00001010 (8 + 2), 1 is 00000001, and 255 is 11111111. The address 10.0.1.0 becomes 00001010 00000000 00000001 00000000.

Every address splits into two parts. The leftmost bits, the network part, are the same for every device on one network. The rest, the host part, differ for each host, meaning any device with an IP address. Your device compares network parts to decide whether a destination is on its own network or must go through a router (lesson 12).

CIDR notation: the number after the slash

CIDR (Classless Inter-Domain Routing) notation writes a block of addresses as its first address, a slash and the prefix length: how many bits, counted from the left, make up the network part.

In 10.0.1.0/24, the first 24 bits are fixed and 8 are free. Each free bit doubles the number of combinations, so 8 free bits give 2 to the power 8, or 256, addresses: 10.0.1.0 to 10.0.1.255.

A /16 leaves 16 free bits: 65,536 addresses, from 10.0.0.0 to 10.0.255.255. A /32 fixes all 32 bits, so it names exactly one address. Each extra prefix bit halves the block: a /25 holds 128 addresses, a /26 holds 64.

Many tools show the same split as a subnet mask: 32 bits with a 1 for every network bit, written like an address. A /24 is 255.255.255.0. A /26 is 255.255.255.192, because its last number is 11000000, or 128 + 64.

In the bit strip, watch where the colour changes. A /24 splits exactly at a dot, but a /26 splits two bits into the last number, so the decimal form hides the boundary: 10.0.1.0/26 ends at 10.0.1.63.

Two strips of 32 boxes holding the bits of 10.0.1.0: 00001010, 00000000, 00000001, 00000000, with 10, 0, 1 and 0 above each group of eight. For 10.0.1.0/24, the first 24 boxes are purple, the network part, and the last 8 cyan, the host part: 256 addresses, .0 to .255, mask 255.255.255.0, split exactly at the last dot. For 10.0.1.0/26, the first 26 boxes are purple and the last 6 cyan: 64 addresses, .0 to .63, mask 255.255.255.192. A note says a /26 splits inside the last number, not at a dot
A /24 splits at a dot; a /26 splits two bits into the last number.

One rule follows: the address before the slash must be the block's first, with every host bit 0. Blocks of 64 start at .0, .64, .128 and .192, so 10.0.1.64/26 is a valid block, but 10.0.1.5/26 is not.

Subnets: carving a big range into smaller ones

A subnet (short for subnetwork) is a smaller block carved out of a bigger one with a longer prefix. In a cloud VPC (virtual private cloud), your own private network inside a cloud provider (see What Is a VPC?), you pick one big private range, then carve a subnet for each tier: a group of servers with one job.

Moving from /16 to /24 turns 8 host bits into network bits. Those 8 bits count from 0 to 255, so 10.0.0.0/16 holds 256 subnets of 256 addresses, 10.0.0.0/24 to 10.0.255.0/24: the third number picks the subnet. In the analogy, the /16 is the society and each /24 is a block.

Separate subnets let you treat tiers differently. Load balancers, which share requests among servers, sit where the internet can reach them; the database subnet accepts traffic only from the app subnet. Lessons 12 and 13 show how.

In the tree, notice how little is used: four /24 subnets take 1,024 of the 65,536 addresses, and one is spare on purpose. Subnets can also differ in size, such as a /20 for app servers and a /26 for databases, as long as none overlap.

Tree diagram. At the top, a VPC range 10.0.0.0/16 with 65,536 addresses; a note says 8 more network bits give 256 possible /24 subnets. Four branches lead to /24 subnets of 256 addresses each: public, 10.0.0.0/24, for load balancers; app, 10.0.1.0/24, for app servers; database, 10.0.2.0/24, for databases only; spare, 10.0.3.0/24, kept for growth. A dashed bar below says 10.0.4.0/24 to 10.0.255.0/24, 252 more /24 subnets, are unused for now
Four subnets use under 2% of the /16, leaving 252 more /24s free.

Usable addresses: why a /24 gives fewer than 256

Traditionally, two addresses in every block are kept from devices. The first, the network address, has every host bit 0 and names the subnet itself. The last, the broadcast address, has every host bit 1 and means "every device on this subnet". So a /24 has 254 usable addresses.

Cloud providers keep a few more. AWS reserves five in every subnet, the first four and the last. In 10.0.1.0/24, those are 10.0.1.0 (network address), 10.0.1.1 (the VPC's router), 10.0.1.2 and 10.0.1.3 (for DNS and future use) and 10.0.1.255, kept although AWS does not support broadcast. That leaves 251.

Other clouds differ, so check. Two prefixes skip the traditional rule: a /32 is a single address, and a /31, two addresses, can number a link joining exactly two devices.

The flowchart turns this into four steps. Notice in the table that AWS's five reserved addresses barely matter in a /16 but take almost a third of a /28.

Flowchart of four steps worked for 10.0.1.0/26. Step 1, read the prefix: 26. Step 2, count host bits: 32 minus 26 is 6. Step 3, count addresses: 2 to the power 6 is 64, since each bit doubles it. Step 4, subtract reserved addresses, which depends on the network: a classic network subtracts 2, giving 62 usable, and an AWS subnet subtracts 5, giving 59. A note says a classic network reserves the first and last address, and AWS the first four and the last. A table: /16 has 16 host bits, 65,536 addresses, 65,534 usable classically and 65,531 on AWS; /24 has 8, 256, 254 and 251; /26 has 6, 64, 62 and 59; /28 has 4, 16, 14 and 11. AWS subnets can be /16 to /28
The same /26 gives 62 usable addresses on a classic network and 59 on AWS.

Planning rules: no overlaps, room to grow

Two ranges overlap when they share even one address: 10.0.5.0/24 overlaps 10.0.0.0/16 because it sits inside it. If two networks you join both use 10.0.0.0/16, an address such as 10.0.1.20 exists on each side, so packets cannot tell which you mean.

So list everything the range may ever need to reach: other cloud networks, the office and the VPN (virtual private network), an encrypted link that puts a laptop on the company network. AWS, for example, will not peer, or directly connect, two VPCs whose ranges overlap. Avoid 192.168.0.0/24 and 192.168.1.0/24 too: many home routers use them.

Then leave room to grow, because resizing hurts: on AWS you cannot change a subnet's range after creating it, only make a new subnet and move the servers. Give the network a generous block such as a /16, size each subnet above today's need, and keep spare blocks.

Check yourself

A teammate wants a /27 on AWS for 20 servers. Is it big enough?

Only just. A /27 has 5 host bits, so 32 addresses, and AWS keeps 5, leaving 27 usable. With so little room to grow, a /26, with 59 usable, is safer.

Do 10.0.1.0/26 and 10.0.1.64/26 overlap, and do both fit inside 10.0.1.0/24?

They do not overlap: the first covers .0 to .63, the second .64 to .127. Both fit inside the /24, because their first 24 bits, 10.0.1, match it.

Your office network is 10.0.0.0/16, and a colleague plans a 10.0.0.0/16 cloud VPC joined to it by VPN. What goes wrong?

Every address exists on both sides, so traffic for, say, 10.0.1.20 cannot reach the right machine. A range that overlaps nothing, such as 10.1.0.0/16, avoids that.