Friday, October 9, 2015

Networking Basics - IP address, netmasks and subnets

In this tutorial, we will cover some networking basics. We won't be hacking anything, but by the end of the tutorial you'll learn a lot of things which will be useful later, especially when you'll use nmap. Please note that it is advised that you go through wikipedia pages of all the concepts covered here since the discussion won't be exhaustive in any way.

IP address

An IP address is simply a 32 bit address that every device on any network (which uses IP/TCP protocol) must have. It is usually expressed in the decimal notation instead of binary because it is less tedious to write it that way. For example,
Decimal notation -
Binary  - 11000000.10101000.00000001.00000001
It is clear from the binary form that the IP is indeed 32 bits. It can range from to (for the binary all 0s and all 1s respectively) [A lot of time, the first octet usually goes upto 127 only. However, we aren't concerned with that here.]

Parts of an IP address

Now this IP address has 2 parts, the network address and host address. A lot of wireless routers keep the first 3 octets (8 bits, hence octets) for the network address and the last octet as host address. A very common configuration being . Here, is the network address and is host address. I hope you can see that the host address can vary from to (though usually 0 and 255 are reserved for the network and broadcast respectively).

Need for Netmasks

But different networks have different needs. The previous configuration lets you have a lot of different possible networks (the first 3 octets are for the network and can take different values, not just but only 256 (254 actually) hosts. Some networks may want more hosts (more than 255 hosts per network). This is why there is no "hardcoded" standard enforced on networks for the network and host addresses, and instead, they can specify their own configuration. The first 3 octets being network address and last octet being host address is common, but in no way mandatory. Using Netmasks, we can have very versatile set of configurations, for each and every need.


A netmask is used to divide the IP address in subnets. 
We'll start with a basic example. Suppose we want to define a netmask which configures our network like wireless router in the previous example. We want the first 3 octets to correspond to the network and next 1 octet for host address. 
Let's think of an operation which we can use to separate the network and host part of the IP address. For simple purposes, we could have just defined after which octet does the host part start [basically saying that anything after the third period(.) is host address]. While this is a simple solution, it is not very versatile. 
A more elegant and mathematical solution was proposed.

Netmask - Working

First I'll tell you the mathematical functionality of a netmask. Assume A to be an IP address and M to be a netmask. Then, 
A & M gives the Network address
A & (~M) gives the Host address.
is bitwise And
~ is bitwise Not (i.e. complement, 1s complement to be more precise)

So, basically a netmask is another 32 bit binary number (just like an IP address), but with the purpose of giving Host address and network address when the operation bitwise and is carried out on it (and it's complement) with A.


You'll understand better with example.
A = is you IP address
M =
We convert it  to binary, and then carry out the desired operations.

A   =    11000000.10101000.00000001.00000001  (
M   =    11111111.11111111.11111111.00000000  (
A&M =    11000000.10101000.00000001.00000000  (
A&M is network IP that we desired

A   =    11000000.10101000.00000001.00000001  (
~M  =    00000000.00000000.00000000.11111111  (
A&~M=    00000000.00000000.00000000.00000001  (
A&~M is host IP that we desired


Basically, if you realize that 11111111 is 255 in decimal, then you can see that for the parts of the IP address that you want for networks, you set the subnet to 255, and for the ones you want for host, you set it to 0.
So, if you want to reserve 2 octets for networks and 2 for hosts, then the subnet will be-
M =
If you want 3 octets for host, then
M =
Hence, we can see that using netmasks we can achieve what we wanted, i.e. to define networks with whatever number of hosts we require. Now we go a bit further.


Now suppose you want to divide your network into parts. It is the sub-networks that are known as subnets (it is correct to call them subnetwork as well). 
We'll jump right to it, consider the netmask M
M = 11111111.11111111.11111111.11000000
Now, the first 3 octets describe the network. But the 4th octet, which is supposed to be for the host, has the 2 most significant bits (i.e. leftmost bits) as 1. Thus, the 2 most significant (leftmost) bits of the 4th octet will show up when we carry out the bitwise AND operation. They will, thus, be a part of the network address. However, they belong to the host octet. Thus, these 2 bits, which belong to the host octet but show up in the network IP address divide the network into subnets. The 2 bits can represent 4 possible combinations, 00, 01, 10 and 11, and hence the network will have 4 subnets. 

Example of Subnetwork

Back to our previous "A",

A   =    11000000.10101000.00000001.xx000001  (
M   =    11111111.11111111.11111111.11000000  (
A&M =    11000000.10101000.00000001.xx000000  (

Earlier, irrespective of what was there in 4th octet of A, we would have got all 0s in 4th octet of A&M i.e. network address. This time we will get the 2 most significant bits in the network address. Four subnets will be formed depending on the value of xx (which can be 00,01,10 or 11). Now, we will see which subnet has which set of hosts.

Which subnet has which hosts

has hosts (00000000 to 00111111)

has hosts (01000000 to 01111111)

has host (10000000 to 10111111)

has host (11000000 to 11111111)

So the netmask M divided the network into 4 equal subnets with 64 hosts each. There are some subnets which are much more complicated and have their applications in certain specific areas. I recommend going through Wikipedia page on Subnetworks to get some more idea. I have covered enough and now you can understand Wikipedia;s content on the topic without any difficulty.

Some Special IPs = All IPs on local machine. Anything hosted on this IP is available to all devices on the network. = LocalHost, this loops back to the machine itself. = Broadcast, anything sent to this IP is broadcasted (like radio is broadcasted to everyone) to all hosts on the network.


You see the notation in this pic?  
This way of representing subnets using /24, /25, /26, etc. is quite useful while doing vulnerability scans on networks (using nmap, etc.). /24 represents the netmask , the first example we took of Wireless router. It is the most common configuration you'll use while doing nmap scan. The one we discussed later, in the subnets section, is /26. It has 4 subnetworks. /25 has 2 subnets. /27 has 8. /31 has 128 subnets! In this subnet, only 2 host can be there per network, and it is used for 1 to 1 or point to point links. I hope the next time you have to deal with networks, you won't be having difficulties. There are topic like Multicast etc. which build up on this, and you can do further reading on them. That was all for this tutorial. Good luck.


  1. Thank you Shashwat! This was really helpful.

  2. Replies
    1. i also want to hack a fb account but how i can do such

  3. excellent content

  4. Thanks for the article. I found two errors. You need to fix them.

    First error.


    ~M = 00000000.00000000.00000000.11111111 (

    A&~M= 11000000.10101000.00000001.00000000 (


    ~M = 00000000.00000000.00000000.11111111 (

    A&~M= 00000000.00000000.00000000.00000001 (

    Second error.


    M = 11111111.11111111.11111111.11000000 (


    M = 11111111.11111111.11111111.11000000 (

    1. Thanks for the corrections. I have made the necessary updates. I was too hasty when writing the dot decimal notation I suppose.

    2. Shashwat, maybe I'm too picky, but the binary notation also needs to be corrected.
      A = 11000000.10101000.00000001.00000001 (
      ~M = 00000000.00000000.00000000.11111111 (
      A&~M= 11000000.10101000.00000001.00000000 ( - wrong!
      A&~M= 00000000.00000000.00000000.00000001 ( - right!
      That's all :)

    3. Thanks for pointing that one out too :)

  5. you should correct that line
    A&~M= 11000000.10101000.00000001.00000000 (

  6. "Thus, the 2 most significant (rightmost)"
    it must be least

    1. sorry, most is correct one. wrong one is rightmost, its leftmost

  7. Interesting, yet over my head. You offer a novice level guide?

  8. how to hack wordpress sites in kali linux......tutorial plz........

  9. Awesome, had a class about this. Everything's seems to be correct and you kept the explanations on a low level that helps many beginners.
    Keep up the good work!

  10. really good work ! good stuff for noobies !
    great job (y)
    do u have any tutorial on advance stuff?

  11. Very informative post! There is a lot of information here that can help any business get started with a successful social networking campaign.

  12. I needed to thank you for this incredible read!! I unquestionably adored each and every piece of it. I have you bookmarked your site to look at the new stuff you post. bezoek website

  13. I am always searching online for articles that can help me. There is obviously a lot to know about this. I think you made some good points in Features also. Keep working, great job! Meer hierover leest je hier

  14. I just want to let you know that I just check out your site and I find it very interesting and informative.. Visit website

  15. My friend recommended this blog and he was totally right keep up the fantastic work! Privacy Online

  16. You made such an interesting piece to read, giving every subject enlightenment for us to gain knowledge. Thanks for sharing the such information with us to read this... 192.168 49.1



    router login
    Positive site, where did u come up with the information on this posting?I have read a few of the articles on your website now,

  18. Thanks for the blog filled with so many information. Stopping by your blog helped me to get what I was looking for. Now my task has become as easy as ABC.

  19. seaport hack Excellent trick this great friend, this was what I was looking for a long time and finally something that works. I recommend them all if it is real is not a lie. Thanks friend. Keep it up

  20. 192.168.l.254 This IP address is used by the routers like TP-Link, Netgear, D-Link uses it as the default IP address.

  21. An IP address is a product address and intended to permit have on one system to speak with a host on an alternate system paying little heed to the kind of LANs the hosts are partaking in. Expert Circle

  22. Great post I would like to thank you for the efforts you have made in writing this interesting and knowledgeable article.

  23. I recommend to write such more post.I also recommend visiting elearning mobile app developer


  24. Routers are the most important devices that are required to get the internet connectivity. There are many brands and router models around the globe. Most people use multiple brand routers, they don't know how to configure them for the perfect usage. Here at we have all the manuals for configuring the router login pages.

  25. Nanocell Networks Pvt Ltd could be a leading organization focused on bringing telecom training solutions everywhere the world. We come up with numerous beneficial telecom training courses on wireless technologies circuit core network, packet core network, transmission technologies and etc. We also provide you 5G Wireless Training to form a bright future on wireless technologies.

  26. Many homework on the continual hunt along with offstage on the road to winning. Definitely not attached, simple to-fall as a result of wayside; And not investigation, afterward into a path travel toward the black. گاد بت


  27. 192.168.l 254 password
    IP address can be used to change the name of the Wi-Fi, control the number of devices that are connected at a time to the network and much more.


  28. check out wood tools review

    All wood tools
    This website is best in reviewing the tools that are used in wood working and gardening. We are a group of specialists who can easily identify the best tools in the field of wood working and gardening. We can find the best tools for you in the required budget. Do check us out.

  29. I can recommend primarily decent and even responsible tips, as a result view it: top article


© Kali Tutorials, 2016. Unauthorized use and/or duplication of this material without express and written permission from this site’s author and/or owner is strictly prohibited. Excerpts and links may be used, provided that full and clear credit is given to Shashwat Chaudhary and Kali Tutorials with appropriate and specific direction to the original content.
Bitcoin: 1B5aLqJcMW7zznffTxQwta8JTZsxBDPguC