Networking 101: Subnetting


 Subnetting means dividing a big network into smaller logical networks in order to reduce the complexities that arise if we had to analyze a huge network as a whole.

Subnetting is an important part of networking.

Subnetting is also an essential part when it comes to CCNA, CompTIA N+, etc.


Here the 255.255.255.0 is the subnet.
The subnet has 4 parts in which each part consists of 8 bits(1's and 0's) so this 255 is actually made up of 8 bits.
If all the 8 1's are active then it becomes 255 and if all 0's are active, it becomes 0. Thus the arrangement of these 0's and 1's determines what that the subnet would be.


128   64   32   16   8   4   2   1        128   64   32   16   8   4   2   1     128   64   32   16   8   4   2   1                   

   1     1     1    1    1   1   1    1           1     1     1    1    1   1   1    1        1     1     1    1    1   1   1    1

                   [255]                                                   [255]                                             [255]

128   64   32   16   8   4   2   1                                                  Hosts available=2^8=256

   0     0     0    0     0   0   0   0
 
                    [0]
                                                                  [Figure A]

Actually, this is how the 255.255.255.0 comes up.
An important thing to note here is that you cannot activate 0's and 1's as per your choice. 
i.e in the above case for the ultimate 8 bits if we want to switch a 0 to 1 then it should be in an order such that the 0 corresponding to 128 would be turned to 1 first and after that the zero corresponding to 64 and so on...
The 255.255.255.0 subnet is also called the /24 subnet and is widely used in households, small businesses, etc.
Now, you may be wondering how did this 2^8 emerge here... The answer to this question is that this number 8 depends on the number of bits available for switching from 0 to 1.
If we switch on the 0 corresponding to 128, then the last 8 bits of this subnet would become something like this:

128   64   32   16   8   4   2   1        128   64   32   16   8   4   2   1     128   64   32   16   8   4   2   1                   

   1     1     1    1    1   1   1    1           1     1     1    1    1   1   1    1        1     1     1    1    1   1   1    1

                   [255]                                                   [255]                                             [255]

128   64   32   16   8   4   2   1                                                  Hosts available=2^7=128

   1     0     0    0     0   0   0   0
 
                    [128]
                                                                  [Figure B]


The subnet address will be 255.255.255.128.
Moreover, the subnet becomes a /25 subnet.
The next bit available for switching on will be the one corresponding to 64.
If we  want to switch the 0 corresponding to 64 on, then the subnet would become a /26 subnet, the number of hosts will be 128+64 i.e 192 and the subnet address would be 255.255.255.192
The amount of hosts that you can have on your private network depends upon the subnet mask and the way that you set it up!
A question must be arising in your mind... Hey what does that /24 stand for and how do you calculate that?
Well, count the number of 1's from left to right in figure A you'll find your answer.
Now as the number of 1's decreases, the number of available hosts increases.

For every 8 bits turned on, the 255 comes up in the subnet.
Let's take an example
If you are told to find the subnet mask for a /24 network, you'll be easily able to find the answer.
24 has 3 8's in it. So the first 3 parts containing 8 bits will be on and the last portion would be 0. i.e 255.255.255.0
Not only that for a subnet we know that the format is xxx.xxx.xxx.xxx right? Each 8-bit series represents the xxx in the address. 
For instance, let's say if someone tells you what will be the subnet mask for /8 network?
See here the number is 8 right? We have to turn all the 8 bits on; so the subnet mask will be 255.0.0.0.
Here is a small table for / networks.

Number                                            Subnet mask
/8                                                       255.0.0.0
/16                                                     255.255.0.0
/24                                                     255.255.255.0
/32                                                    255.255.255.255


Also, an easy way for reference would be making a chart like this...


                   1          2         3         4         5       6      7       8
                   9         10        11       12      13     14     15     16
                  17        18        19       20      21     22     23     24  
                  25        26        27       28      29     30     31     32  
                              
Hosts:       128       64       32       16       8       4       2       1                                                                                                 
Subnets:    128      192      224     240    248    252    254    255


From this, we can answer questions related to / networks.
eg. What is the subnet mask  for /10 network so you can say it will be 255.192.0.0
Each time you cross a number that is in multiple of 8, the subnet will have a 255 included in it.
i.e. if someone asks you to find the subnet mask of /28 network;
here you have crossed 8,16 and 24 so the address will be 255.255.255.x
now for the x you can refer to the chart; the subnet corresponding to 28 is 240 as you can see.
How do we find the number of hosts then?
Remember only if all 32 bits are 1 will there be no host available so starting back from 32,31,.... you can write 2^n hosts
eg for the bit number 32, the number of hosts will be 2^0=1, for bit number 31, the number of hosts will be 2^1=2, for bit number 30, hosts will be  2^2=4 and soon and ultimately for bit number 1, the number of hosts will be 2^31=214748648.

Always remember that when it comes to potential hosts, we have to subtract 2 from the actual hosts.
Why subtract 2? These 2 addresses are reserved for your Network Address and Broadcast Address.



As you can see in the above picture, your subnet mask is 255.255.255.0 so firstly, what is the kind of network that we're using? If you think that it's a /24 network then... bravo!! You're absolutely correct.
Now you might see the broadcast IP and the inet here. Now, the 0 in 255.255.255.0 means that you can have any number between 1-255 in place of this 139 in the inet address and currently you're at 139. 
The odds of the address 192.168.57.0 being used as your Network Address and as you see 192.168.57.255 is already being used as your Broadcast Address. So one can say that the first and the last addresses in the series are reserved as network and broadcast addresses respectively. This is not always necessary but for the majority of the time, it does exist in this way.

Thus now whenever you see an IP Address given to you which is something like 192.168.2.5/16 then immediately things will start to click that since its a /16 network, the subnet mask will be 255.255.x.x and it could have up to 2^16=65536 hosts.
Big organizations mostly use large networks such as /16,/20, etc because a lot of devices come under them.

If you want more information about the network address and broadcast address, you can visit ipaddressguide.com/cidr.

So that's the end of our networking series.


If you like the content then do consider connecting with me and pour your knowledge into my DM!!😇 

Instagram: bhavak_29

LinkedIn: https://www.linkedin.com/in/bhavak-kotak-3b6b071b1/

:NOTE:

All the images belong to their respective owners.

I am a learner so I learn things from different sources and I DO NOT claim that any of the content(if it does) belonging to someone else as mine.

Also a huge thanks to Heath Adams(AKA The Cyber Mentor). It is because of his course that I am motivated to put this content here and I have taken inspiration from his videos to a considerable amount of extent and tried to convey what I understood in the best way possible.











Comments

Popular posts from this blog

Defeating RootME

TCS HACKQUEST PLAYGROUND WALKTHROUGH

OWASP TOP 10 Explained