Have you ever been confused by this notation at the end of an IP address?
This is called the CIDR (Classless Inter-Domain Routing), and it represents a block of IP addresses. In this post, you'll learn how to calculate that range in your head.
In an IP, each block refers to 8 bits (an octet). Usually, we convert each block to decimal to make it more readable, e.g.,
192.168.1.1. The CIDR represents a right-padded bitmask that's applied to the IP address.
/8 corresponds to
11111111.00000000.00000000.00000000 and the more readable subnet mask
How many addresses does a CIDR block represent? You simply calculate
prefix is the number after the slash.
232-29=23=8 addresses. Here's a quick table that you can reference for the most CIDR blocks.
It's easy arithmetic to calculate how many subnets can fit inside a larger one. For example, how many
/30 networks fit in a
/27 network? Using the properties of exponents, it's easy.
232-27/232-30 = 25/22= 25-2 = 23 = 8
To calculate the exact range that an IP and CIDR block corresponds to is a bit more difficult to do in your head. For small blocks, it's simple. For larger blocks, it might be tough to do the math in your head (although it's the same!). There are a host of calculators online that can calculate the first and last usable IPs based on the command, like cidr.xyz.
As a caveat, you should remember that each range should reserve an address for the network and broadcast addresses, so the effective number of addresses is two fewer than what you calculated.