Understanding CIDR Notation and IP Address Range

Michel Burnett
5 min readSep 22, 2020

--

This article will help you become familiar with IP addresses and CIDR notation.

Finding out what IP addresses are usable within a range can be tricky for people who are not familiar with networking. This article will help you whether you’re trying to find the correct IP range for AWS when configuring VPCs and subnets or just want to understand what the numbers in your IP address mean.

Example IP address.

Let’s begin with dissecting this sample IP address. The numbers separated by periods “174.16.0.0” are a numerical representation of underlying binary digits (For example “10101110” is represented by “174”). The first three numbers usually represent the network bits (address used to identify network/subnet) and the last number usually for the host bits (address used to identify a host/destination).

Easy system to count binary octets.

This is an easy system in case you’re unfamiliar with binary numbers. Each bit is either “1” to represent “on” or a “0” to represent “off”. All 8 bits in an octet (0.0.0.0.0.0.0.0) can be represented by numeric value (128.64.32.16.8.4.2.1) and the bit within the octet decides whether that value is “on” or “off”. So to write “2” as a binary octet you would write “00000010” and to write “3” as a binary octet you would write “00000011”.

Example of a packet being sent from the web to 174.16.0.1

Here’s an example of a packet that would be sent from the web to your device when you make a request to a website. You can imagine this packet being filled with information you’re downloading and waiting to receive. When the packet is sent from the web it is given the appropriate IP address it needs to arrive to. In this case our “174.16.0.1” is interpreted in two layers. First “174.16.0.0” (the network bits) tells the network that this packet is destined for the 174.16.0.0 subnet. Your modem/router with a host address of 0.0.0.1 would be a part of this subnet and would pick up that packet. The packet would then be routed to the device that requested it by your router.

So far so good but this brings up an issue of scarcity. Each number represents 8 bits (called an octet) for a total of 32 bits. This means that the total number of possible IP addresses is 2³⁶ (~4 billion). This finite number becomes a problem when you consider there’s twice the amount of people in the world than available IP addresses, not to mention people who have different IP addresses for their laptop, phone or even washing machine. This is where CIDR notation comes in.

CIDR Classless Inter Domain Routing.

CIDR notation saved us from running out of IP addresses with some neat mathematics. An easy way to understand CIDR is to think of the notation on the end as the amount of bits that will be allocated to the network. In this example “/24” would mean that the first 24 bits are allocated to the network (10101110.00010000.00000000) and the remaining 8 bits would be allocated to the host (.00000000). Another way of writing “/24” would be “11111111.11111111.11111111.00000000” the 1s representing the first 24 bits as “on”. This could also be written as “255.255.255.0” which is called the “subnet mask”.

The host bits are what we need to identify an IP range. In IP addresses, the host bits reserve all 0s (00000000) for the network address and all 1s (11111111) for broadcasting address. Because those are always used we subtract 2 from our possible IP addresses. The first usable IP address will then be the network bits “00000000”+1 (00000001) . In this example that would mean “174.16.0.0” is the network address and “174.16.0.1” is the first usable IP address. The last usable IP will be the host bits all turned on except the last (11111110). In this example that would be “174.16.0.254”. For this example, our IP range would be “174.16.0.1/24” to “174.16.0.254/24”. So what happens when the CIDR notation tells you there’s more or less than 24 network bits ?

In this example the host bits are separated by a red line. In our first example we know there are 8 host bits remaining (because 32 bits in total minus 24 network bits = 8 host bits). This means that the total possible IP addresses in this range are 2⁸ (256 total IP addresses minus 2 addresses reserved for network and broadcasting). In the next example we’ve moved the red line to illustrate only having 6 host bits left (because 32 bits minus 26 network bits = 6 host bits). That means the total possible IP addresses in this range are 2⁶ (64 total IP addresses minus 2 addresses reserved for network and broadcasting).

Now our CIDR notation tells us that there will be 16 network bits and 16 host bits. Our method will work the same but overlap into the network bits. With more host bits there will be many more usable IP addresses in this range. The total possible IP addresses in this range would be 2¹⁶ (65536 total IP addresses minus 2 addresses reserved for network and broadcasting). Services like AWS limit the amount of host bits you can use as to not waste any unused IP addresses (typically they have an allowable subnet mask/CIDR notation range of /16 to /28).

Hopefully this article has demystified the concept of CIDR notation for you and you can now comfortably choose an appropriate IP address or range without wondering what all the seemingly random numbers mean.

--

--