What is Subnetting and general understanding
During my student life I have studied Subnetting in networking course, but as I moved towards programming and have not studied it more in more detail, now one of our client wants us to create network related application which needs Subnetting knowledge.
As non network person it is hard for me to study it in detail and give it enough time to understand, I googled for it, read few articles and luckily I am able to code it now.
I want to share my knowledge with other programmers so if they need to code something related to Subnetting they can easily understand it here.
What is Subnetting?
Subnetting is breaking up one large physical network into more than one small logical networks, in other words partitioning large network into many small networks.
Physically all the hosts remains at same position and location but logically they are member of different networks. and after Subnetting now they have different access levels.
Why do we need Subnetting?
In many organizations there are multiple departments, they all need different access level to public and private networks, some departments have shared data for other departments, some need high speed internet connection, some of them have highly confidential data which needs to be strictly secured.
I such cases if they make every thing secure they will might loose data sharing or high speed internet to those who require it, similarly looking at each department you will find them different from another.
that why we need to divide one large network into many small networks. and keep each department into that small logically separate network, we can divide each small network into further sub networks too. this way we can assign different policies to each sub network as it is logically different that other sub networks so the policies applied to one sub-network will not affect other network directly.
Advantages of Subnetting
The following are advantages of Subnetting
- Performance and Speed
- Reduced network congestion
- Scalable network
- Easy administration and Troubbleshooting
Disadvantages of Subnetting
I can’t guess disadvantages of Subnetting
- It may require extra networking devices
How to do Subnetting?
It is just to connect a subnetwork hosts to separate switch/router/firewall and change their IPs/subnetmask.
Calculating IPs for Subnetworks
Before starting calculating we must have a bit knowledge about networking. that is
we have 4 IP classes (A,B,C,D)
I will not go in detail about these, In most cases we will be using Class C that ranges from 192.0.0.0 to 220.127.116.11
Suppose we are using 192.168.0.0 upto 192.168.0.255 with subnetmask 255.255.255.0 we can have one large network of 254 hosts, the remaining 2 IPs are reserved for (network-ip and broadcast-ip)
Note: In each network or subnetwork 2 IPs (first and last) are reserved for network-ip and broadcast-ip respectively which normally can not be assigned to any host. by host I mean a client (PC, Printer, Thin Client) etc.
How many subnetworks can we create?
By default we get one network, we can divide it into the following using given subnetmask and CIDR. (Consider CIDR is short form of subnetmask for now).
|Subnetmask||CIDR||Total Networks||IPs in each network|
|255.255.255.254||/31||128||2 (both can be used in special cases)|
|255.255.255.252||/30||64||4 (4-2 hosts)|
|255.255.255.248||/29||32||8 (8-2 hosts)|
|255.255.255.240||/28||16||16 (16-2 hosts)|
|255.255.255.224||/27||8||32 (32-2 hosts)|
|255.255.255.192||/26||4||64 (64-2 hosts)|
|255.255.255.128||/25||2||128 (128-2 hosts)|
|255.255.255.0||/24||1||256 (256-2 hosts)|
Form the above table you can decide which type of subnetwork you need, how many subnetworks you need and how many hosts you need. It is not mandatory to have all same size subnetworks, you can go with 1 subnetwork of 128 IPs, 1 subnetwork of 64 IPs and subnetorks 2 of 8 IPs but IPs in all those subnetworks should not repeat.
In above example I took 192.168.0.0 if your IP is different you can use Subnetting calculator to get your possible networks, which will provide you all IP ranges in each subnetwork. I have also created an online free Subnetting calculator at subnetting-calc.codingsips.com/ you an use that.
Subnetting calculation Logic
Internally it is all calculated in binaries, I am not very good to explain it here, but I learnt and coded Subnetting calculator by glancing at above table.
Look at above table and try to reverse-engineer and try to make algorithm for it.
Just note and remember in IP octects we can give 0 to 255 which becomes 256. 256 is lucky number here.
Look at each column try to break the pattern, it all changes with 2 power n and than subtrict or divide by 256
|Row 1||2 power 1 = 2 IPs in n/w||256/2=128 Total Networks||256-2 = 254 subnetmask octect|
|Row 2||2 power 2 = 4 IPs in n/w||256/4=64 Total Networks||256-4 = 252 subnetmask octect|
|Row 3||2 power 3 = 8 IPs in n/w||256/8=32 Total Networks||256-8 = 248 subnetmask octect|
|Row 4||2 power 4 = 16 IPs in n/w||256/16=16 Total Networks||256-16 = 240 subnetmask octect|
|Row 5||2 power 5 = 32 IPs in n/w||256/32=8 Total Networks||256-32 = 224 subnetmask octect|
|Row 6||2 power 6 = 64 IPs in n/w||256/64=4 Total Networks||256-64 = 192 subnetmask octect|
|Row 7||2 power 7 = 128 IPs in n/w||256/128=2 Total Networks||256-128 = 128 subnetmask octect|
|Row 8||2 power 8 = 256 IPs in n/w||256/256=1 Total Networks||256-256 = 0 subnetmask octect|
I am sure if you read it few time and look at last two tables side by side you will understand. I would suggest you to open same link in 2 tabs or browsers and analyze side by side.
do not forget to play with my mysbetting calculator at subnetting-calc.codingsips.com/
I have developed android application named
Subnet Calc it is simple having decent layout and animation, try it I am sure you will this app.