What a subnet mask actually is
Every IPv4 address is 32 bits long, usually written as four decimal numbers separated by dots — for example 192.168.1.42. But an address on its own does not tell a device where the boundary between “my local network” and “everywhere else” sits. That boundary is exactly what the subnet mask supplies.
A subnet mask is also 32 bits. Read left to right, it is a run of 1 bits followed by a run of 0 bits — always in that order, never mixed. The 1 bits mark the network portion of the address; the 0 bits mark the host portion. Two devices are on the same subnet — and can talk directly without a router — when the network portion of their addresses is identical.
When your computer wants to send a packet, it lines the destination address up against its own address and mask. If the network portions match, it delivers the packet directly on the local link. If they differ, it hands the packet to the default gateway (your router) to forward onward. That single comparison is the entire job of the mask.
The binary intuition: why 255.255.255.0 = /24
The reason 255.255.255.0 is the most common mask you will ever see is that 255 is what you get when all eight bits of a byte are 1 (11111111 in binary is 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = 255), and 0 is all eight bits off. So this mask is:
255.255.255.0
11111111.11111111.11111111.00000000
└────────── 24 ones ──────────┘└ 8 zeros ┘Twenty-four 1 bits, then eight 0 bits. Counting the leading 1 bits is exactly what CIDR notation does: it writes the mask as a slash followed by the number of network bits. Twenty-four network bits is /24. So 255.255.255.0 and /24 are two ways of writing the same thing.
Every byte in a mask is one of just nine values, because the 1 bits have to be contiguous from the left: 0 (00000000), 128 (10000000), 192 (11000000), 224 (11100000), 240 (11110000), 248 (11111000), 252 (11111100), 254 (11111110), and 255 (11111111). If you ever see a mask byte that is not on this list — say 255.255.100.0 — it is malformed.
A few masks you will meet constantly: /8 is 255.0.0.0, /16 is 255.255.0.0, /24 is 255.255.255.0, and /25 is 255.255.255.128 (the fourth byte is 10000000 = 128).
CIDR notation and prefix lengths
CIDR stands for Classless Inter-Domain Routing. Before CIDR, IPv4 was carved into rigid “classes” (A, B, C) with fixed 8-, 16-, and 24-bit boundaries, which wasted enormous amounts of address space. CIDR threw that out in favour of a simple idea: the network boundary can sit at any bit position, and you just state where with a prefix length from /0 to /32.
The prefix length is the count of network bits. Everything to its right is host bits. Because IPv4 has 32 bits total, the number of host bits is always 32 − prefix. That single subtraction drives every other number:
- Host bits =
32 − prefix - Total addresses in the block =
2^(32 − prefix) - Usable host addresses =
2^(32 − prefix) − 2(for ordinary subnets — you subtract the network and broadcast addresses)
The smaller the prefix number, the bigger the network. A /16 holds 65,536 addresses; a /24 holds 256; a /30 holds just 4. Every step of +1 on the prefix halves the block size.
Worked example 1: 192.168.1.0/24
Start with the classic home-network block 192.168.1.0/24. The prefix is 24, so there are 32 − 24 = 8 host bits, and 2^8 = 256 total addresses. To find the key addresses:
- Network address — set all host bits to
0. That is192.168.1.0. This names the subnet itself; it is not assigned to any device. - Broadcast address — set all host bits to
1. The last byte becomes11111111= 255, giving192.168.1.255. A packet sent here reaches every host on the subnet. - Usable host range — everything in between:
192.168.1.1through192.168.1.254. - Usable host count —
256 − 2 = 254.
This is why a typical home router hands out addresses like 192.168.1.100 and reserves 192.168.1.1 for itself: they all share the 192.168.1 network portion, so every device on the LAN can reach every other device directly.
Worked example 2: 10.0.0.0/22 (a non-/24 block)
A /24 is easy because the boundary lands neatly on a byte. Most of the confusion in subnetting comes from prefixes that split a byte in the middle. Take 10.0.0.0/22. The prefix is 22, so there are 32 − 22 = 10 host bits and 2^10 = 1024 total addresses.
The mask for /22 is 255.255.252.0. The third byte is 11111100 = 252, meaning the first 6 bits of that byte are network and the last 2 are host. Blocks therefore step through the third byte in multiples of 4: 10.0.0.0, 10.0.4.0, 10.0.8.0, and so on.
- Network address —
10.0.0.0. - Broadcast address — the block spans four full third-byte values (0, 1, 2, 3), so it ends at
10.0.3.255. - Usable host range —
10.0.0.1through10.0.3.254. - Usable host count —
1024 − 2 = 1022.
Notice that 10.0.4.0 is not part of this subnet — it is the network address of the very next /22. Getting the block boundaries right is the whole skill, and it is exactly what a CIDR calculator is for.
Worked example 3: 192.168.1.0/26 (splitting a /24 into four)
Now split a byte the other way. A /26 has 32 − 26 = 6 host bits, so 2^6 = 64 addresses per block, and 64 − 2 = 62 usable hosts. The mask is 255.255.255.192 (the last byte is 11000000 = 192).
Because each block is 64 addresses wide, a single 192.168.1.0/24 divides cleanly into four /26 subnets:
192.168.1.0/26— network192.168.1.0, broadcast192.168.1.63, hosts.1–.62.192.168.1.64/26— network192.168.1.64, broadcast192.168.1.127, hosts.65–.126.192.168.1.128/26— network192.168.1.128, broadcast192.168.1.191, hosts.129–.190.192.168.1.192/26— network192.168.1.192, broadcast192.168.1.255, hosts.193–.254.
Four subnets of 62 usable hosts each — a common way to hand different departments or VLANs their own slice of a larger block while keeping the numbering tidy.
Why subnetting exists
Splitting one big network into several smaller ones is not busywork — it buys real benefits:
- Segmentation and security. Putting guests, IoT gadgets, and trusted workstations on separate subnets lets you apply firewall rules between them. A compromised smart bulb on one subnet cannot freely reach a file server on another.
- Smaller broadcast domains. Broadcast traffic stays within a subnet. One flat network of thousands of hosts drowns in broadcast chatter; carving it into
/24s keeps each segment quiet. - Efficient allocation and routing. CIDR lets an ISP hand out exactly the size of block a customer needs and lets routers summarise many small networks behind one prefix, keeping global routing tables far smaller than per-network entries would. The reverse operation — collapsing adjacent blocks into one — is called aggregation, and there is a CIDR aggregator for it.
Private ranges recap
The addresses in these examples — 192.168.x.x and 10.x.x.x — are not random. They come from the RFC 1918 private ranges reserved for internal use and never routed on the public internet: 10.0.0.0/8, 172.16.0.0/12, and 192.168.0.0/16. You can subnet within any of them freely because they are yours to number however you like behind NAT. For the full picture of why these exist and how they differ from routable addresses, see public vs private IP addresses.
A quick note on IPv6 prefixes
IPv6 uses the same prefix-length idea — a /64 means 64 network bits — but the arithmetic feels different because addresses are 128 bits wide instead of 32. The near-universal convention is to give every LAN a /64, which leaves 64 host bits: roughly 1.8 × 1019 addresses per subnet. There is no address scarcity to fight, so you almost never subnet below /64, and there is no network/broadcast pair to subtract — IPv6 dropped broadcast entirely in favour of multicast. If you are comparing the two protocols, the IPv4 vs IPv6 explainer covers the wider differences.
Common mistakes
- Forgetting to subtract 2. A
/24has 256 addresses but only 254 usable hosts. The network and broadcast addresses cannot be assigned to a device. - Assuming the boundary is always on a byte. It is only tidy at
/8,/16, and/24. A/26or/22splits a byte, so the block steps are 64 or 4 — not 1 or 256. - Picking a host address that is really a boundary.
10.0.4.0looks like a host in10.0.0.0/22but it is the next subnet's network address. Always check where your block actually ends. - Confusing the mask with the address.
255.255.255.0is a mask;192.168.1.0is a network address. They are written the same way but mean different things. - Writing an illegal mask. The
1bits must be contiguous from the left.255.255.0.255is not a valid mask because the1bits are not all on the left.
Try it now
The fastest way to build intuition is to type a block into a calculator and watch the numbers move. Open the CIDR calculator, enter 192.168.1.0/26, and confirm the network, broadcast, and host range match the worked example above. Then try 10.0.0.0/22 and watch the block end at 10.0.3.255. Once the calculator stops surprising you, you have understood subnetting. If you want to see how an address maps to its raw 32-bit integer, the IP to decimal converter makes the binary concrete.
Frequently asked questions
What does 255.255.255.0 mean as a subnet mask?
In binary it is twenty-four 1 bits followed by eight 0 bits. The 1 bits mark the network portion and the 0 bits mark the host portion, so it is identical to the CIDR prefix /24. It leaves 8 host bits, giving 256 addresses per subnet and 254 usable for devices.
How many usable hosts are in a /24 subnet?
A /24 has 8 host bits, so 2^8 = 256 total addresses. Two are reserved — the network address (192.168.1.0) and the broadcast address (192.168.1.255) — leaving 254 usable, from 192.168.1.1 to 192.168.1.254. In general it is 2^(32 − prefix) − 2.
Why are IPv6 prefixes usually /64 instead of small like IPv4?
IPv6 addresses are 128 bits wide, so there is no need to conserve space. Every LAN gets a /64, leaving 64 host bits — about 1.8 × 1019 addresses each. Features like SLAAC assume that 64-bit host portion, so you rarely subnet below /64, and there is no network/broadcast subtraction.
Related reading
- CIDR calculator — enter any block and get the network, broadcast, mask, and host range instantly.
- CIDR aggregator — collapse adjacent subnets into the smallest set of prefixes.
- Public vs private IP — where the RFC 1918 ranges in these examples come from.
- IPv4 vs IPv6 — why v6 prefixes and
/64subnets work differently. - IP to decimal — see the 32-bit integer behind a dotted-quad address.
- Networking glossary — quick definitions for the terms used here.
