CIDR Binary Calculation

How Classless Inter-Domain Routing notation maps to binary — subnet masks, network prefixes, host bits, and the bitwise logic that makes routing decisions at line speed.

Network server racks for CIDR binary subnet calculation
What Is CIDR? CIDR in Binary Network vs Host Bits Subnet Mask Calculating Addresses VLSM FAQ

What Is CIDR?

Classless Inter-Domain Routing (CIDR) is the way we describe IP address blocks today. Before CIDR, we had classful addressing — Class A, B, and C networks — where you were stuck with fixed-size blocks of 16 million, 65,536, or 256 addresses. It was wasteful. CIDR replaced that in the mid-1990s, and every router since has been using CIDR to figure out where packets go.

At its core, CIDR is a compact notation: an IP address followed by a slash and a number, like 192.168.1.0/24. The number after the slash — the prefix length — tells you how many of the leftmost bits are the network prefix. Everything after those bits is the host portion. That /24 is the key to everything: it tells a router exactly how many bits to compare when deciding if a destination is on the same network.

I have used CIDR binary calculations extensively when designing VPC architectures on AWS. A /20 subnet is 4096 addresses, and knowing that the binary mask has 20 leading ones helped me spot a route table misconfiguration before deploying to production.

CIDR vs Classful Addressing

A /24 gives you 254 usable hosts — the same as the old "Class C" block. But CIDR lets you go finer: /25 (126 hosts), /26 (62 hosts), /27 (30 hosts), all the way up to /32 (a single host). This granularity is what makes modern IP address allocation practical. ISPs can give you exactly the block size you need instead of forcing you into rigid class boundaries.

CIDR in Binary — The Breakdown

Here is where the bitwise logic comes in. An IPv4 address is 32 bits long, period. CIDR notation tells you how to split those 32 bits. Take 192.168.1.0/24 — I hear that one more than any other because it is the default subnet on almost every consumer router on the planet.

192.168.1.0 in Binary (32 bits)

192.168.1.0 — Full 32-bit Binary
192  =  11000000
168  =  10101000
1    =  00000001
0    =  00000000

Full: 11000000.10101000.00000001.00000000

The /24 Split

Now add the /24. That means: the first 24 bits belong to the network, and the remaining 8 bits are for hosts. Visually, the 32-bit address splits like this:

/24 — 24 Network Bits + 8 Host Bits
11000000.10101000.00000001.00000000

← 24 network prefix bits   ← 8 host bits

Network address: 192.168.1.0  (all host bits 0)
Broadcast address: 192.168.1.255  (all host bits 1)
Usable range: 192.168.1.1 through 192.168.1.254
/24 = 24 network bits + 8 host bits = 254 usable addresses

The bitwise operation happening here is straightforward: the router applies the subnet mask (which is also 32 bits of 1s and 0s) to the destination IP using a bitwise AND. If the result matches the network address, the destination is local. Otherwise, the packet goes upstream.

Network Bits vs Host Bits

Every CIDR prefix length is a simple arithmetic relationship:

Network bits + Host bits = 32

/24: 24 network bits + 8 host bits   2^8 = 256 total addresses
/16: 16 network bits + 16 host bits  2^16 = 65,536 total addresses
/8:   8 network bits + 24 host bits   2^24 = 16,777,216 total addresses
/30: 30 network bits + 2 host bits    2^2 = 4 total addresses
/32: 32 network bits + 0 host bits    1 address (a single host)

The number of usable host addresses is always total addresses minus 2 — the network address (all host bits 0) and the broadcast address (all host bits 1) are reserved. In binary, these two special addresses are the only ones where all host bits are identical, making them trivially detectable in hardware.

Let me show you a different prefix to make this concrete. A /26, which I use frequently when segmenting office VLANs:

/26 — 26 Network Bits + 6 Host Bits
Example: 10.0.0.0/26

Subnet mask: 255.255.255.192
Binary mask: 11111111.11111111.11111111.11000000

Subnets per /24: 4
Hosts per subnet: 2^6 - 2 = 62 usable addresses
Block size: 64 addresses per subnet
/26 = 62 usable hosts per subnet, 4 subnets per /24 block

The Subnet Mask in Binary

The subnet mask is the unsung hero of CIDR. It is a 32-bit value where every bit in the network portion is set to 1 and every bit in the host portion is set to 0. The router uses it in a bitwise AND with the destination IP to extract the network address.

Common Subnet Masks in Binary

CIDRSubnet MaskBinaryUsable Hosts
/8255.0.0.011111111.00000000.00000000.0000000016,777,214
/16255.255.0.011111111.11111111.00000000.0000000065,534
/24255.255.255.011111111.11111111.11111111.00000000254
/25255.255.255.12811111111.11111111.11111111.10000000126
/26255.255.255.19211111111.11111111.11111111.1100000062
/27255.255.255.22411111111.11111111.11111111.1110000030
/28255.255.255.24011111111.11111111.11111111.1111000014
/29255.255.255.24811111111.11111111.11111111.111110006
/30255.255.255.25211111111.11111111.11111111.111111002

Notice the pattern: each /24 increment adds 8 ones to the binary mask. Each /1 increment within an octet doubles the number of network bits. When I am working with network ACLs or firewall rules, I often write out the subnet mask in binary to verify my logic — especially when dealing with non-octet-aligned prefixes like /23 or /21 where the boundary falls in the middle of an octet.

/23 — Boundary in the Middle of an Octet
Binary mask: 11111111.11111111.11111110.00000000
Subnet mask: 255.255.254.0
Block size: 512 addresses (2 /24s)
Usable hosts: 510

/23 is the boundary that trips up most people — the third octet has 7 network bits,
so the subnet mask in that octet is 254 (11111110), not 255.

Calculating Network and Broadcast Addresses

Here is the bitwise logic that runs in every router for every packet. Given an IP and a subnet mask, the router calculates three things: the network address, the broadcast address, and the host range.

Network Address

The network address is the bitwise AND of the IP and the subnet mask. Every bit in the host portion gets zeroed out.

Network Address: 10.0.50.37/20
IP:  10.0.50.37  =  00001010.00000000.00110010.00100101
Mask: /20       =  11111111.11111111.11110000.00000000
-------------------------------------------------- &
Net:  10.0.48.0   =  00001010.00000000.00110000.00000000

The /20 mask zeros out the last 12 bits (host portion).
Broadcast (all host bits 1): 10.0.63.255
Usable range: 10.0.48.1 through 10.0.63.254
/20 = 4096 total addresses, 4094 usable hosts

Broadcast Address

The broadcast address sets all host bits to 1. It is the network address plus the bitwise complement of the subnet mask within the host portion. Every device on the subnet listens to this address — it is how ARP requests and DHCP offers find their way.

Quick Calculation: Network + (2^HostBits - 1)
Given: 172.16.4.0/22
Host bits: 32 - 22 = 10 bits
2^10 = 1024 addresses per block

Network address:  172.16.4.0
Broadcast address: 172.16.4.0 + 1023 = 172.16.7.255
Usable range:      172.16.4.1 to 172.16.7.254

Binary verification (/22 mask = 255.255.252.0):
Mask: 11111111.11111111.11111100.00000000
The third octet has 6 network bits, so block size = 2^2 = 4 in the third octet.
/22 = 1024 addresses, 1022 usable hosts

Variable Length Subnet Masking (VLSM)

One of the practical realities I deal with regularly is that not every subnet needs the same number of hosts. Your data center VLAN needs 500 addresses. Your printer VLAN needs 10. Wasting a whole /24 on the printer VLAN is pointless. This is where Variable Length Subnet Masking (VLSM) comes in — using different prefix lengths within the same major network.

VLSM is just CIDR applied hierarchically. You take a larger block and carve it into smaller blocks of different sizes, each aligned to a power-of-two boundary. The bitwise constraint is that subnets cannot overlap — their network addresses must be multiples of their block size.

VLSM Example: Carving 10.0.0.0/24
Block: 10.0.0.0/24 (256 addresses)

/25 subnet 1:  10.0.0.0/25   (0-127,  126 usable)
/25 subnet 2:  10.0.0.128/25 (128-255, 126 usable)

Or more granular:
/26 subnet A:  10.0.0.0/26   (0-63,   62 usable)
/26 subnet B:  10.0.0.64/26  (64-127, 62 usable)
/27 subnet C:  10.0.0.128/27 (128-159, 30 usable)
/27 subnet D:  10.0.0.160/27 (160-191, 30 usable)
/28 subnet E:  10.0.0.192/28 (192-207, 14 usable)
/28 subnet F:  10.0.0.208/28 (208-223, 14 usable)
/30 link A:   10.0.0.224/30 (224-227, 2 usable)
/30 link B:   10.0.0.228/30 (228-231, 2 usable)
One /24 carved into 8 subnets of varying sizes, zero wasted space

Notice that subnets must align to their block size boundaries. A /27 has a block size of 32, so its network address must be a multiple of 32. This is why 10.0.0.128 works for /27 (128 is evenly divisible by 32) but 10.0.0.140 would not. In binary, this constraint is trivially visible: the last 5 bits of a /27 network address must be 0.

Calculate CIDR Ranges Visually

Enter any IP and CIDR prefix in our bitwise calculator to see the full binary breakdown — network bits highlighted, host bits separated, subnet mask constructed automatically.

Frequently Asked Questions About CIDR Binary Calculation

What does /24 mean in CIDR notation?

In CIDR notation, /24 means the first 24 bits of the IP address are the network prefix, and the remaining 8 bits are for host addresses. This gives you 256 total addresses (2^8) with 254 usable host addresses after reserving the network and broadcast addresses. The subnet mask for /24 is 255.255.255.0.

How do I convert a CIDR notation to a subnet mask in binary?

A /24 in CIDR means 24 consecutive 1-bits followed by 8 zero-bits. In binary, that is 11111111.11111111.11111111.00000000. Split by octets: each octet is 8 bits. Three octets of all 1s (255.255.255) and one octet of all 0s (0). The general rule is: for /N, write N ones followed by (32-N) zeros, then group into four 8-bit octets.

How many hosts can a /24 subnet have?

A /24 subnet has 8 host bits, giving 2^8 = 256 total IP addresses. However, two addresses are reserved: the network address (all host bits 0, e.g., 192.168.1.0) and the broadcast address (all host bits 1, e.g., 192.168.1.255). This leaves 254 usable host addresses (256 - 2 = 254) for devices like computers, routers, and servers.

What is the binary representation of 192.168.1.0/24?

192.168.1.0 in binary is 11000000.10101000.00000001.00000000. With /24, the first 24 bits (11000000.10101000.00000001) are the network prefix, and the last 8 bits (00000000) are for host addresses. The network address is 192.168.1.0 (all host bits 0), and the broadcast address is 192.168.1.255 (all host bits 1).

What is the difference between /24 and /16 in binary?

/24 means 24 network bits and 8 host bits (subnet mask 255.255.255.0), giving 254 usable hosts. /16 means 16 network bits and 16 host bits (subnet mask 255.255.0.0), giving 65,534 usable hosts. In binary: /24 = 11111111.11111111.11111111.00000000, while /16 = 11111111.11111111.00000000.00000000. The fewer network bits you have, the more host addresses are available.

Related Tools

Bitwise Calculator →

AND, OR, XOR, NOT, shifts

Bitwise Guide →

Complete operations reference

Hex to ASCII →

Decode hex strings

SHA256 Generator →

Compute hashes