NetCalcLab

CIDR notation explained

Where CIDR came from, why the prefix length replaced network classes, and how to read the slash notation you meet in routing tables, firewall rules and cloud consoles.

Before CIDR: fixed classes

Until 1993, the first bits of an IPv4 address determined its size. A first octet starting with 0 meant class A and 16,777,216 addresses; a first octet starting with 10 meant class B and 65,536 addresses; starting with 110 meant class C and 256 addresses. The boundaries were hard, and there was no way to ask for anything in between.

The classful address system
ClassLeading bitsFirst octetDefault maskAddresses per network
A01–126255.0.0.016,777,216
B10128–191255.255.0.065,536
C110192–223255.255.255.0256
D1110224–239—Multicast, no per-network sizing
E1111240–255—Reserved for experimental use

Two problems compounded. First, waste: an organisation that needed 2,000 addresses had to take a class B and leave 63,000 unused. Second, routing table growth: every class A, B or C allocation became a separate entry in the global routing table, regardless of its size.

What CIDR changed

CIDR removed the fixed boundaries and replaced them with an explicit prefix length. A network of 1,000 addresses is now a /22 — 1,024 addresses, 4% waste instead of 98%. Two consequences followed, and both were the point of the change.

  • Efficient use of space. An allocation can be sized to the requirement rather than to the next class up, so the address space lasts far longer.
  • Route aggregation. Because addresses are no longer tied to class boundaries, an ISP holding 203.0.112.0/21 can advertise one route for all eight of its /24s. Aggregation is what kept the global routing table manageable through the 1990s and is still what makes the internet scale today.
The same network in four notations
192.168.1.0/24
Prefix length    24
Subnet mask      255.255.255.0
Wildcard mask    0.0.0.255
Inverse form     192.168.1.0 0.0.0.255  (Cisco ACL syntax)

Reading a prefix length without counting

Counting bits from scratch is unnecessary once you know the last-octet sequence. Prefixes longer than /24 only ever involve the fourth octet, and the mask values follow a fixed progression.

The last-octet mask sequence
PrefixLast octetBinary of last octetBlock sizeUsable hosts
/24000000000256254
/2512810000000128126
/26192110000006462
/27224111000003230
/28240111100001614
/292481111100086
/302521111110042
/312541111111022 (RFC 3021)
/322551111111111

The pattern is that each step adds one bit to the network portion, so the mask octet gains the next place value: 128, then 64, then 32, and so on. Reading /27 as 224 is a matter of recognising the sequence rather than doing arithmetic.

Longest prefix match in practice

The reason a prefix length has to be a contiguous run of bits is that routers resolve ambiguity by choosing the longest matching prefix. Consider a router with three routes:

Route selection
10.0.0.0/8        via 192.0.2.1
10.1.0.0/16       via 192.0.2.2
10.1.2.0/24       via 192.0.2.3

Destination 10.1.2.55 matches all three.
Longest match wins -> 10.1.2.0/24 via 192.0.2.3

This is what allows a specific exception to be carved out of a broad summary. The /8 carries most of the traffic; the /24 provides a more specific path for one subnet without needing to break the /8 into pieces. If masks could be non-contiguous, no single number would express specificity and the algorithm would fall apart.

Where you meet CIDR notation

  • Routing tables. Every route is a prefix and a next hop. The default route is 0.0.0.0/0 and appears in every router's table.
  • Firewall rules. Source and destination ranges are written as prefixes, and the choice of prefix directly determines how much traffic matches.
  • Cloud networking. VPC and VNet address ranges are specified as CIDR blocks, and subnets are carved out of them — which means the prefix arithmetic determines whether your subnets fit at all.
  • Vendor configuration. Interface addresses, OSPF network statements and route summarisation all use prefixes, and Cisco ACLs use the wildcard form of the same information.
  • IPv6. The same notation applies with a range of /0 to /128, and a /64 — the standard subnet size — is so common that IPv6 subnetting is usually a question of how many /64s fit in an allocation rather than of masks.

Common mistakes

  • Writing an address that is not the network address. 192.168.1.5/24 is a valid notation but the network is 192.168.1.0/24. Most systems accept and normalise the first form, but it is misleading in documentation.
  • Assuming a larger number means a larger network. /28 is smaller than /24. The number counts network bits, so more bits means fewer host addresses.
  • Confusing the prefix with the mask. A /24 is not “24 hosts” — it is 24 network bits and 254 usable hosts. The two numbers are easy to transpose when reading quickly.
  • Using a non-contiguous mask. 255.255.0.255 looks plausible but is invalid and cannot be expressed as a prefix length, so no router will accept it.

Prefix range summary

Prefix ranges by usage
RangeTypical useNotes
/0Default routeMatches every address; the last resort in a routing table
/1 – /7Historic class A aggregatesRarely seen outside very large routing tables
/8 – /15ISP and cloud allocationsA /8 is 16,777,216 addresses
/12RFC 1918 private block172.16.0.0/12 is the private range
/16 – /22Enterprise and campusA /16 contains 256 /24s for subdivision
/23 – /24Site and VLAN networksA /24 is the standard LAN size, 254 hosts
/25 – /29Department segmentsDivides a /24 into smaller broadcast domains
/30WAN links (classic)Two usable hosts out of four addresses
/31WAN links (RFC 3021)Two addresses, no waste
/32Host routesLoopbacks and single-destination static routes

For IPv6 the same table shifts by 96: a /64 is the standard LAN size, a /128 is a single host, and a /127 is the analogue of an IPv4 /31 for point-to-point links.

Related: CIDR calculator, CIDR reference table, subnetting guide, VLSM design guide.

Frequently asked questions

What does CIDR stand for and when was it introduced?

Classless Inter-Domain Routing. It was introduced in RFC 1518 and RFC 1519 in 1993 to replace the fixed class A, B and C boundaries, which had proved far too coarse for a growing internet. CIDR introduced the prefix length, allowing a network of any size from a /32 single host up to a /0 default route.

How is a prefix length different from a subnet mask?

They express exactly the same information in different notations. A prefix length counts the network bits, so /24 means 24 ones. A subnet mask writes those same bits out in dotted-decimal, so /24 is 255.255.255.0. Every prefix has exactly one valid mask, and every valid mask maps back to exactly one prefix.

Why was classful addressing a problem?

Class A gave 16 million addresses, class B gave 65,536 and class C gave 256, with nothing in between. An organisation needing 1,000 addresses had to take a class B allocation and waste 98% of it, and each of those allocations added a route to the global routing table. By the early 1990s the routing table was growing faster than routers could handle and the address space was being consumed far faster than necessary.

What does the slash notation look like in practice?

It appears after an address, as in 192.168.1.0/24 or 2001:db8::/32, and it can also stand alone when the prefix is all you care about, as in a routing table entry or a firewall rule. Cloud consoles usually show it as a separate field labelled 'prefix' or 'CIDR'.

What is the longest and shortest possible prefix?

For IPv4 the range is /0 to /32. A /0 matches every address and is used as the default route. A /32 matches exactly one address and is used for host routes and loopback interfaces. For IPv6 the range is /0 to /128, because an IPv6 address is 128 bits.

Can a subnet mask be non-contiguous?

No. A valid mask is a run of 1 bits followed by a run of 0 bits, with no interleaving. 255.255.0.255 is not a valid mask because there is a zero between ones. This restriction exists because the network/host division has to be expressible as a single prefix length, which is what makes longest-prefix-match routing possible.

What is longest prefix match?

When a router has several routes that could match a destination, it chooses the one with the longest prefix — the most specific match. A /32 host route beats a /24 subnet route, which beats a /16 summary, which beats the /0 default. This is what allows a small exception to be carved out of a large aggregate without disturbing the rest of it.