people inside a maze
Fri Nov 18

The Complete Guide to Subnetting

In a network, each device requires an identifier to communicate with each other. In computer networks, IPv4 is commonly used.

With a format like 192.168.1.2, each part consists of 8 bits (octets) separated by periods. IPv4 (often called as IP address), basically consists of 2 parts, the network address and the host address.

The network address is used by all devices that are members of the same network to be able to communicate with each other. Let’s take the example of the IP address above. We can assume 192 168.1.x as the network address and x.x.x.2 as the host address. However the portion could be shifted based on the subnet mask.

By default, within a range of IP addresses, the first and the last IP will be reserved. The first one will be used as the default gateway and the last one becomes the broadcast address. It is between these two addresses that the IP addresses can be used by the devices.

For example, if your router IP (default gateway) is 192.168.1.0 and broadcast is 192.168.1.255, then your available IP for your devices are between 192.168.1.1 - 192.168.1.254.

Your home desktop computer might be assigned to the IP address 192.168.1.2, your Android assigned to the IP address 192.168.1.3, the Raspberry pi be assigned to 192.168.1.4, etc.

Understanding Binary

Before learning further about subnet, it is imperative to know about binary. Let’s take a single octet and see how the binary works.

You might have heard about the 8 bit octet chart which is something like this. For example, we take a single number like 112.

1286432168421

Base2 (binary)

The binary calculation follows this. Now, compare to our numbering system which is base 10.

100000001000000100000100001000100101

Base10 (decimal)

In our numbering system (decimal), the number 112 is between 100-1000. Since we have the exact number of 112, we can just simply say 112.

In binary, it has no concept like 112. It only has 2 digits number 0 and 1. In order to get a particular number, we need to sum it up to get the exact number we need. Looking at the chart above, our number is between 64-128.

Because we know that every part of IPv4 consists of 8 bits. We can use the binary chart above to get the number we want. We can use 64 + 32 + 16 = 112. So we could say that the binary number of 112 is 01110000.

What if we want 121? Just do it the same way like 64 + 32 + 16 = 112. However, we need 9 to get 121 from 112. So, we can use 8 + 1 = 9. Therefore we get a new octet which is 01111001.

1286432168421
8-bit octet chart01111001
------------------------

Binary representation of (121)

Result
0 + 64 + 32 + 16 + 8 + 0 + 0 + 1 = 121

What if we want 119? We can use 64 + 32 +16 = 112. We need to add 7 to get the number. Since we can’t use 8, we need another number which we can get from 4+2+1 = 7. Therefore, the binary would be 01110111.

As you can see now, the minimum and maximum number of a single binary octet is 00000000 which is equal to 0 and 11111111 which is equal to only 255. By knowing the binary, it would be easier to understand how the IP address correlates with the subnets.

How does IP address and Subnet Mask correlate?

Let’s take a look at the binary level of our known IP. Our devices belong to the network address 192.168.1.0. In binary, it is the same as 11000000.10101000.00000001.00000000. If we define the subnet mask to be 255.255.255.0 or 11111111.11111111.11111111.00000000, it will look like this.

19211000000
11111111
------------------------

255

16810101000
11111111
------------------------

255

100000001
11111111
------------------------

255

000000000
00000000
------------------------

0

Network address| Host address
Network Address & Subnet Mask

So what does it mean? As stated before, an IP address consists of two parts, the network address and host address. When the binary digit of the subnet mask is 1, it indicates that this part is occupied as a network address. On the contrary, 0 means the part is available for the host address.

Take a look at another example of IPv4 and subnet mask below.

17210101100
11111111
------------------------

255

1700010001
11111111
------------------------

255

000000000
00000000
------------------------

0

000000000
00000000
------------------------

0

Network address| Host address
Network Address & Subnet Mask

As you can see, the host address space is twice as big as the first example. The subnet mask can be further modified to 255.0.0.0 or to something like 255.255.192.0 where 1 only fills the first and second bit on the third octet.

What is subnet and why do subnetting?

Subnet is basically splitting the logical network into smaller part of network

In a company, where hundreds of devices need to include a network. It is impractical to join every device with only a single network. Why is that? Some of the reasons are manageability, separation, and performance.

Think of it like this. A company has a hundred computers to connect to the internet while at the same time able to communicate with each other. It is common for a company to have multiple departments such as finance, marketing, human resource, and so on.

Let’s say that this company only has one network and assume there are 100 computers within this network with IP addresses ranging from 192.168.1.2 - 192.168.1.102.

To run its function, some protocol needs to do broadcasting. Take an example of ARP.

What it does is basically resolving IP addresses to the device MAC address. While doing its job, ARP will broadcast packets asking the MAC address of the assigned IP address.

The broadcasting will affect all devices connected to the same network. While it was done, only by a single device, it won’t matter much. But what if it was done by every device together at the same time?

There is a real possibility of total chaos where the entire connection will suffer, giving a huge network performance impact. Moreover, the size of the network makes it harder to address and specify the real issue.

Because of this, the network needs to be broken down or divided into smaller networks so that the potential for network congestion can be reduced, therefore improving network performance as well.

By using several routers, these networks can be connected to each other, so that these networks are still able to communicate. This is where the role of subnetting becomes critical.

/24, /25 , /26: What is that?

Subnet masks are often written with /24, /25, /26, also known as CIDR Notation. This shows how big the portion of the host address that can be used by the host. Let’s take an example of an IP address like 192.168.1.0/26.

If we parse it into binary form, the IP and subnet mask can be written as follows.

19211000000
11111111
------------------------

255

16810101000
11111111
------------------------

255

100000001
11111111
------------------------

255

000000000
11000000
------------------------

192

Network Address Length = 26 bits
Host Address Length = 6 bits
Network Address & Subnet Mask

On the subnet mask section above, 26 bits are used as the network address, while the rest can be used as the host address. As we know, the first and the last IP address will be reserved as a network address and broadcast address. Thus, the available IP for the host always needs to be subtracted by 2.

Referring to 8-bit binary octets, this type of subnet mask can also be written as 255.255.255.192.

Exercise

Let’s take an example
We have a target IP address of 26.148.10.60/26.
From the IP, specify some of the parameters below.

IP address
Network
First Host
Last Host
Broadcast
Next subnet

Answer
The subnet mask used is /26. In binary form, the subnet would be like this.

11111111

First Octet

11111111

Second Octet

11111111

Third Octet

11000000

Fourth Octet

Using the table below, we can see how many subnets and hosts can be made.

Subnet/24/25/26/27/28/29/30/31
Number of Subnets1248163264128
Number of IPs256128643216842

We will use this table as a guide. Now, look at the number of bits used in /26. As previously explained, each octet has a range between 0-255. In other words, the total is 256.

By looking at this table, we can see that subnet /26 has 4 subnets, each of which has 64 IP addresses. If parsed, the IP range will range from

  • 26.148.10.0 - 26.148.10.63
  • 26.148.10.64 - 26.148.10.127
  • 26.148.10.128- 26.148.10.191
  • 26.148.10.192 - 26.148.10.255

Because in each range, two IPs will be reserved as network addresses (first) and broadcast (last), the total IP available for hosts is 62. Thus, the parameters are as follows.

| IP address | | ----------- | ------------ | | Network | 26.148.10.0 | | First Host | 26.148.10.1 | | Last Host | 26.148.10.62 | | Broadcast | 26.148.10.63 | | Next subnet | 26.148.10.64 |

Conclusion

We have learned about the basics of IP address and subnet mask, how they are related, and why subnetting is important for network performance and management. We have also learned how to use binary to calculate the number of subnets and hosts, and how to use CIDR notation to write subnet masks. By understanding these concepts, we can design and configure networks more efficiently and securely. As the internet continues to grow and evolve, IP address and subnet mask will remain essential tools for network communication. Therefore, it is important to keep learning and practicing these skills in order to keep up with the changing demands of the digital world.