Subnetting, calculation explained

Fatah Nur Alam Majid
3 min readMar 17, 2017

In computer network, we know we can do some subnet calculation to achieve the most efficient IP allocation. This way, we can make a “VLSM network” that has efficient use of IP address. But do you know how to do that calculation? Well, in this post I will try to tell you how to calculate subnet mask to achieve VLSM, thus achieving efficient IP address usage. But I limit it only for IPv4, because to be honest, I don’t know yet the IPv6 until now lol.

Okay lets go to the explaination then..

Now assume we have an IP address 172.17.50.233 with subnet mask 255.255.240.0 or we can say with CIDR notation /20. With information given, we can first specify the network address, broadcast address, and usable host address range.

As we know, in the IP addressing scheme we find two parts of every IP address. We call them network portion and host portion. We can find both of them when we get the IP address and its subnet mask. First we can translate the subnet mask from decimal into binary. In example above it’s 255.255.240.0 or 11111111.11111111.11110000.00000000 (you can check it by calculating them back into decimal notation). If we count the one(s), we get 20 of ones. And from this counter, we can specify the CIDR notation of /20, because actually the CIDR notation is just counting the ones in subnet mask.

Go to the next step. We can first translate the IP address into binary notation. In the example above it is 172.17.50.233 or 10101100.00010001.00110010.11101001 (I hope you really cross-checked it). Then we can overlay the both binary notation so we can find the network portion and the host portion.

11111111.11111111.11110000.00000000

10101100.00010001.00110010.11101001

From looking at that two binaries, the portion where the subnet bit is 1 (the bold one) is called the network portion, and where the subnet bit is 0 (the italics), they’re​ called host portion. This means, we get 12 bit of host addresses that you can assign them into your hosts (we can get 2¹²-2 of real hosts).

So you may be wondering, why we must subtract 2 from the total addresses​? The answer is simple, because we need to assign the network address and the broadcast address. To know what address they’re using, is just a piece of cake. When we get the host portion from an IP address, you can change them into all zero for finding your network address (you must work with binaries first, then convert it back into decimal for use). Then, you can change the all-zero-bit in the host portion into all one for finding the broadcast address.

As you can see, we’re already assign 2 addresses from our total addresses, thus in every subnetting calculation we must count this 2 addresses as a must-exist address for address allocation (but you may want to allocate 3 addresses instead of 2, because we also need an address for gateway per subnet). In this case, the network address is 172.17.48.0 and the broadcast address is 172.17.63.255 (you can re-calculate the address to make sure what are you counting).

After we know the network address and the broadcast address, we can easily find the usable host addresses​ for our hosts. I tell you, the usable host address start from network address plus one, and ends at broadcast address minus one. So, in this case, our usable host addresses is 172.17.48.1 until 172.17.63.254 (our gateway address is included in this usable addresses, conventionally the address is the last​ usable address or the first usable address to be used).

But remember, the minimum subnet mask we can use is /30. Why? Because in the /30 mask, we only have 2 bits of host portion, means that we can only have 4 addresses (only 2 usable addresses because we need to assign the network address and the broadcast address). This mask is usually used for connection between router.

I think that’s all about subnetting calculation that you must really understand. Thanks for reading my post, and see you again in the next post~

--

--

Fatah Nur Alam Majid

Tech hobbyist, Learn from scratch, Learning the hard way, Just want to share anything