IPV4 address is 32 bit long in binary number system. However, it is usually represented as 4 numbers in dotted decimal format as follows:
10.10.10.1
The four numbers can be converted to binary as follows:
1010.1010.1010.1
To keep the address length as 32 bit in binary, we add zeros to the left side of the numbers as follows:
00001010.00001010.00001010.00000001
Prefix Length
IPV4 addresses are also followed by a value known as prefix length.
For example,
10.10.10.1/30
By combining IPV4 address and prefix length, we can find out the following:
 The number of unique addresses in a network.
 The number of devices that can be connected in the network.
In order to find out the above information, we need to go through the following steps:
Step 1. Convert the IPV4 address in 32 bit binary
In decimal,
10.10.10.1/30
In binary,
00001010.00001010.00001010.00000001
Step 2. Separate the address in two parts based on the prefix length. The length of the left part shall be equal to the prefix length.
00001010.00001010.00001010.000000 01
<30 bits > <2 bits>
The left part is known as the network part, while the right part is called the host part.
Step 3. Create a binary sequence starting from zero using the host bits while keeping the network bits the same.
00001010.00001010.00001010.000000 00
00001010.00001010.00001010.000000 01
00001010.00001010.00001010.000000 10
00001010.00001010.00001010.000000 11
Step 4. Convert the addresses in decimal
10.10.10.0
10.10.10.1
10.10.10.2
10.10.10.3
Hence, in this case we find out that the total number of unique addresses is 4. The first address in this network is called network ID. In this case, it is 10.10.10.0. This address is used to represent the network itself.
The last address in this network is called broadcast ID. In this case, it is 10.10.10.3. This address is used to send broadcast messages to all the devices in the network which is necessary for various purposes.
These two addresses, the network ID and broadcast ID, thus cannot be assigned to any devices in the network.
Hence, the number of addresses that can be assigned to the devices in this network is 2.
Calculation of number of devices that be connected from prefix length
For a prefix length n, we can find out the following:
Number of network bits = prefix length = n
Number of host bits = (32  Number of network bits)
Number of unique addresses = 2^(Number of host bits)
Number of devices that can be connected = Number of unique addresses 2
For example, let us find out the number of devices that can be connected in /27 network.
Number of host bits = (3227) = 5
Number of unique addresses = 2^(5) = 32
Number of devices that can be connected = 32 2 = 30
More importantly, IP addresses of devices in a particular network have the same network ID.
Thus, if two devices have IP addresses 10.10.10.1/30 and 10.10.10.2/30, they are part of the same network with network ID 10.10.10.0.
Subnet Mask
Prefix Length can also be represented as an IPV4 address known as subnet mask. To convert prefix length into subnet mask value follow these steps:
 For prefix length of n, write n number of 1s and rest 0s, making the total length of 32 bits. In case of /30 prefix length, the number of 1s is 30. Number of 0s is 2.
11111111.11111111.11111111.11111100  Convert into decimal
255.255.255.252
Hence, /30 prefix length is equivalent to subnet mask 255.255.255.252.
Prefix length calculation
We can also calculate the prefix length from the number of devices to be connected as follows:
Step 1. Convert the number of devices into binary.
Step 2. Calculate the number of host bits, which shall be equal to the length of the number in binary.
Step 3. Calculate the network bits, which can be calculated by deducting host bits from 32. The length of network bits is the prefix length.
For example, let us find out the prefix length for connecting 50 devices.
50 in binary is 110010
Number of host bits = 6
Number of network bits = 32 6 = 26
Thus, prefix length = /26
The total number of devices that can be connected in a /26 network is 62.

