Subnet Masks and CIDR Notation Made Simple

A subnet mask tells a device which part of an IP address is the network and which part is the individual host, and CIDR notation just writes the same information as a slash followed by the number of network bits. 255.255.255.0 and /24, for instance, both say "the first 24 bits are the network" — leaving 254 usable host addresses.

Why subnets exist

An IPv4 address runs 32 bits long, and every single one splits into two parts: a network prefix shared by all devices on the same subnet, and a host part unique to each device. When your laptop wants to send a packet, it checks the destination against its own network prefix. Match, and it delivers the packet directly on the local network. No match, and off it goes to the default gateway — your router — to get forwarded onward.

Why bother splitting address space into subnets at all? It lets organisations size networks to fit, keep broadcast traffic contained, and apply security rules between different groups of devices. New to addressing in general? Start with what an IP address is first.

How a subnet mask works in binary

A subnet mask is also a 32-bit number, written in the same dotted format as an IP address, and it always takes the form of a run of 1 bits followed by a run of 0 bits — nothing else. The 1s mark the network portion; the 0s mark the host portion.

255.255.255.0  = 11111111.11111111.11111111.00000000   (24 ones)
255.255.255.192 = 11111111.11111111.11111111.11000000  (26 ones)

So how does a device find which network an address belongs to? It runs a bitwise AND between the address and the mask — each bit stays a 1 only when it's a 1 in both. Take the host 192.168.10.77 with mask 255.255.255.192: the first three octets pass through untouched, and the last octet works out like this:

77  = 01001101
192 = 11000000
AND = 01000000 = 64

Which puts the host on network 192.168.10.64. Want to practise this by hand? The IP Address Converter will show any address in binary.

CIDR notation

Writing out a full dotted mask every time is clumsy, so modern networking leans on Classless Inter-Domain Routing (CIDR) notation instead: the network address, a slash, then the number of 1 bits in the mask. 192.168.10.0/24 simply means the mask has 24 ones — that is, 255.255.255.0.

CIDR arrived in 1993 to replace the old "classful" system, where networks came in exactly three sizes: Class A (/8), Class B (/16) and Class C (/24). Those fixed sizes wasted huge swaths of addresses — an organisation needing just 300 addresses had no choice but to take a whole Class B with 65,534. CIDR lets a prefix be any length you need, and it's described today in RFC 4632. You'll still hear people say "a Class C" when what they mean is a /24.

CIDR to subnet mask reference table

The number of addresses in a subnet works out to 2 raised to the number of host bits (that's 32 minus the prefix length). In a normal subnet two of those addresses are spoken for already: the first is the network address and the last is the broadcast address, so usable hosts come out to the total minus two.

CIDRSubnet maskTotal addressesUsable hosts
/8255.0.0.016,777,21616,777,214
/9255.128.0.08,388,6088,388,606
/10255.192.0.04,194,3044,194,302
/11255.224.0.02,097,1522,097,150
/12255.240.0.01,048,5761,048,574
/13255.248.0.0524,288524,286
/14255.252.0.0262,144262,142
/15255.254.0.0131,072131,070
/16255.255.0.065,53665,534
/17255.255.128.032,76832,766
/18255.255.192.016,38416,382
/19255.255.224.08,1928,190
/20255.255.240.04,0964,094
/21255.255.248.02,0482,046
/22255.255.252.01,0241,022
/23255.255.254.0512510
/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
/31255.255.255.25422 (point-to-point links only)
/32255.255.255.25511 (a single host)

The most common subnet on home networks is /24 — which is exactly why so many routers hand out addresses from 192.168.1.2 all the way to 192.168.1.254.

Worked example: 192.168.10.0/26

Say you need to split 192.168.10.0/24 into four equal subnets, one per department. Borrow 2 bits from the host part and you get a /26.

  1. Subnet mask: 26 ones works out to three full octets of 255 plus 11000000 in the fourth octet — which is 192. So the mask is 255.255.255.192.
  2. Block size: 32 − 26 = 6 host bits, and 26 = 64 addresses per subnet. Or take the shortcut: 256 minus the last non-255 mask octet, i.e. 256 − 192 = 64.
  3. Network address: 192.168.10.0 (the first address).
  4. Broadcast address: 192.168.10.63 (the last address, 0 + 64 − 1).
  5. Usable host range: 192.168.10.1 to 192.168.10.62 — 62 hosts, in other words.
  6. Wildcard mask: 0.0.0.63, simply the inverse of the subnet mask, and something you'll see in some router access lists.

Here's how the four subnets making up that original /24 break down:

SubnetNetworkUsable rangeBroadcast
192.168.10.0/26192.168.10.0.1 – .62192.168.10.63
192.168.10.64/26192.168.10.64.65 – .126192.168.10.127
192.168.10.128/26192.168.10.128.129 – .190192.168.10.191
192.168.10.192/26192.168.10.192.193 – .254192.168.10.255

And it lines up with the binary example above: host 192.168.10.77 falls in the second subnet, the one whose network address is 192.168.10.64.

Tip: Want to double-check your work? Type any address and prefix, such as 192.168.10.77/26, into the Subnet Calculator, and it shows the network, broadcast, host range, mask and wildcard instantly.

Special cases: /31 and /32

/31 for point-to-point links

Under the normal rules a /31 would give you two addresses and zero usable hosts — pretty useless. RFC 3021 changed that for point-to-point links, a cable strung between two routers, say: since there are only ever two devices on that link, there's no need for a network or broadcast address at all, so both addresses can be assigned. That saves half the addresses compared with burning a /30 on every link, and most modern router operating systems support it.

/32 for a single address

A /32 describes exactly one address, nothing more. You'll run into it in firewall rules ("allow 203.0.113.5/32"), routing tables for host routes, loopback interfaces on routers, and cloud security groups. It's not a subnet you can actually put several devices on.

A brief note on IPv6

IPv6 keeps the same prefix-length idea but drops dotted subnet masks entirely. Addresses run 128 bits, and the standard size for a single LAN segment is a /64 — 64 bits of network prefix, 64 bits for hosts. Features like Stateless Address Autoconfiguration (SLAAC) depend on that full 64-bit host part, which is why splitting a LAN smaller than /64 is discouraged. A single /64 holds 264 addresses, something like 18.4 quintillion. And since IPv6 has no broadcast address at all (it uses multicast instead), the "minus two" rule simply doesn't apply here. ISPs typically delegate a larger prefix still, a /56 or /48, so customers can carve out many /64 subnets of their own. Read more in IPv4 vs IPv6.

Frequently asked questions

What subnet mask should I use at home?

255.255.255.0 (/24) is the default on nearly every home router, and its 254 usable addresses are plenty for most households. Bigger homes or small offices juggling lots of devices sometimes step up to a /23 or /22.

Why are two addresses unusable in a subnet?

The first address is spoken for by the network itself, and the last is the broadcast address used to reach every host at once — neither one can go to a device, except in the /31 and /32 special cases covered above.

Is a subnet mask like 255.255.0.255 valid?

No. A valid mask has to be a continuous run of 1 bits followed by 0 bits, full stop. Values like 255.255.0.255 or 255.255.255.100 simply aren't valid subnet masks.

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

A wildcard mask is just the bitwise inverse of a subnet mask — 255.255.255.0 becomes 0.0.0.255. You'll see wildcard masks instead of subnet masks in some router configurations, notably access control lists and OSPF on Cisco gear.

Kendiniz deneyin

Bu rehberi ücretsiz araçlarımızla uygulamaya geçirin.

Yorumlar

Bir ipucu paylaşın, soru sorun ya da aracın işinize nasıl yaradığını anlatın.

Okumaya devam edin

Panoya kopyalandı