• IPv4 Subnetting TechNotes

    IP Addressing

    IP addressing refers to assigning a 32-bit logical numeric address to a network device. Every IP address on the network must be unique. An IP address is represented in a dotted decimal format, for example:

    As you can see the address is divided in 4 parts, these parts are called octets. IP is defined at Layer 3 (Network layer) of the OSI model and is routable. In order to be routable a network address must have two parts: a network and a host portion. Subnet masks are used to determine which part represents the network portion and which part represents the host portion. By default the subnet mask is based on the class to which the IP address belongs. The following table lists the classes and corresponding values of the first octet (in the IP address) and the default subnet mask.

    Major classes First octet Default mask
    Class A 1 - 126
    Class B 128 - 191
    Class C 192 - 223
    For example in a Class B IP address, with the default Class B 16-bits subnet mask of, the network portion is 172.16 and the host part is 12.234. We’ll cover this in more detail in a bit.


    Before we go to actually calculating subnets (i.e. subnetting) I want to stress the meaning of the word “subnet mask”. As the name implies, it is a mask that determines what portion of an IP address is the (sub-)network portion. Combined with knowing the class of the IP address it also determines the number of subnets. Although that automatically gives us the host portion as well, it important to realize the class does not influence the number of hosts in a subnet. For example, a class A network with a subnet mask of allows for 254 hosts, which is the same for a class B or class C network with the same subnet mask of

    So to determine the maximum number of hosts in a (sub-)network, all you need to know is the subnet mask, or even better: the “prefix”. The class and even the IP address itself are irrelevant when it comes to calculating the maximum number of hosts.

    For example, a typical subnetting exam questions might present you with an IP address and a subnet mask or prefix and ask for the total number of hosts and/or subnets. Let’s say the network address is To determine the number of hosts we need to translate the mask to a prefix, because that gives us the maximum number of bits we have left for hosts. In this case the prefix is /27 (we’ll get to translation process in detail later) which leaves 5 bits from the 32 bits in an IPv4 address in total. So that’s 5 bits for hosts, which is 5^2 = 32. However, the first address is the network address for the subnet, and the last is the broadcast address, so we need to subtract 2 for those, leaving us with 30 addresses for hosts.

    Now, what if the IP address would have been, or Or if no IP address was mentioned at all and all we got to go on was the mask? Exactly, it would have made no difference to the number of maximum hosts. So to conclude, the subnet mask doesn’t merely determine what portion of a given IP address is the network portion and what portion is for host, but by itself, without any additional info, a subnet mask can tell you directly how much space it allows for host addresses “per subnet”.

    More often we (also) need to know the number of subnets, for which we need one more piece of info than just the subnet mask or prefix, and that’s the class of the IP address. The IP address itself is again irrelevant, except for the first octet, which as shown in the intro above determines the class.
    So far we stressed the importance of knowing the prefix and knowing the default subnet mask for the major IP address classes. There is one more thing you need to add to your subnetting toolkit, or actually should be in there already, and that is basic binary math. In particular there are two essential “formulas” you cannot do without:

    1. Calculate the maximum number of different decimal values a given amount of bits can represent:

    This is really basic binary math. 1 bit allows for 2 different values, 2 bits allows for 4 different values, 3 bits allow for 8 different values. So for every bit you add, the number of possible different values doubles. This can also be written as b^2 where b is the number of bits. Memorizing the first 10 or so is as easy as learning basic multiplication tables back in high school:

    1 bit – 2 values
    2 bits – 4 values
    3 bits – 8 values
    4 bits – 16 values
    5 bits – 32 values
    6 bits – 64 values
    7 bits – 128 values
    8 bits – 256 values
    9 bits – 512 values
    10 bits – 1024 values

    Again, extending the list is easy because all you need to do is double the previous amount of values for every bit you add. Just remember to start with 2 for the first bit (value 0 and value 1).

    The b^2 formula is used to determine the maximum number of subnets and the maximum number of hosts per subnet. For example if you have a class B network with a prefix of /18 you have 2 bits for subnets, which according to the formula and table above means space for 4 different subnets.

    When determining the maximum number of hosts in a subnet you need to subtract 2 of the results, one for the network address of the subnet and one for the broadcast address. So basically the formula for hosts is (b^2) - 2.

    2. Translate octets from their binary value to their decimal equivalent and back.

    The second “bit” of binary math you need to master is translating 8 bits (a byte) to its decimal equivalent (an octet). So instead of looking for the maximum number of different values, we’re going to determine the actual decimal value a given number of bits represent.

    Each octet represents 8 bits, for example the IP address mentioned earlier can also be displayed in dotted binary format: 10011111.01100101.00000110.00001000

    Converting the decimal address to a binary format (and vice versa) is a fairly easy process. The lowest decimal number you can represent with 8 bits is 0 (when all bits are zero, as in turned off), the highest is 255 (all bits turned on) as shown in the following translation table:

    1 1 1 1 1 1 1 1
    128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = 255
    Note that we start counting from the right. For example, 00001101 is the same as 1101, which is:
    0 0 0 0 1 1 0 1
    0 + 0 + 0 + 0 + 8 + 4 + 0 + 1 = 13
    Another example:
    1 0 1 0 1 0 1 0
    128 + 0 + 32 + 0 + 8 + 0 + 2 + 0 = 170
    And some more examples:
    Binary Decimal
    00000000 0
    00000011 3
    10000000 128
    10000001 129
    10111111 191
    11111010 250
    Needless to say it’s important to memorize the translation table, but as you can see it’s not hard to remember because just like the table with the maximum number of values, the value doubles for every bit. The difference is that this table starts with 1 and it’s convenient to write it from right to left.

    Although this works for IP addresses and subnet masks, the latter are a little special. In subnet mask the bits are always consecutive. For example, the subnet mask is written in binary as 11111111.00000000.00000000.00000000 and the subnet mask 255.255.240 is written as 11111111.11111111.11110000.00000000. The number of consecutive ‘1’ bits equals the prefix. So for the first example, the subnet mask, the prefix is 8 bits, and for the last example, the subnet mask 255.255.240, the prefix is 8+8+4=20 bits. To determine the decimal value for the third octet (11110000) we add up the first 4 values (1 for each bit turned on) in our translation table, starting from the left: 128+64+32+16 = 240.

    After some practice this should become basic and easy math, but since the bits in a mask are always consecutive there is a limit to amount of possible values in a mask. Specifically the following 8:

    8 bits = 11111111 = 128+64+32+16+8+4+2+1 = 255
    7 bits = 11111110 = 128+64+32+16+8+4+2= 254
    6 bits = 11111100 = 128+64+32+16+8+4 = 252
    5 bits = 11111000 = 128+64+32+16+8 = 248
    4 bits = 11110000 = 128+64+32+16 = 240
    3 bits = 11100000 = 128+64+32 = 224
    2 bits = 11000000 = 128+64 = 192
    1 bits = 10000000 = 128 = 128
    0 bits = 00000000 = 0 = 0

    Simplified the table looks like this:
    8 bits = 255
    7 bits = 254
    6 bits = 252
    5 bits = 248
    4 bits = 240
    3 bits = 224
    2 bits = 192
    1 bits = 128
    0 bits = 0

    The decimal values on the right are the only valid values you will find in a subnet mask and I highly recommend memorizing this table (and if needed dump it on the sheet you get during the exam for quick reference). Besides translating individual octets, the table above is very helpful to determine the prefix based on the subnet mask. For example, the subnet mask obviously equals a prefix of 8+8+2= /18. The other way around is almost as easy and becomes more obvious when written in binary format. For example, if you take the prefix /25 and write it in binary format you end up with:


    This according to our table, if we translate the octets individually, is Basically for every prefix above /8 you subtract 8 and write an octet of 255 until you have 8 bits or less left.

    Determine the network and broadcast address

    Besides calculating the number of subnets and hosts, another common task regarding subnetting is to determining the network and broadcast address for a given subnet. The network address is the first address in a subnet and the broadcast address is the last address. For example, in the class C network using the default subnet mask (a prefix of /24), the network address is and the broadcast address is When you divide this network into subnets, each subnet will get its own network address and broadcast address. For example, if we divide it into two subnets by using a subnet mask of, the network address of the first subnet is and the broadcast address is The network address for the second subnet would be and the broadcast address

    In a class C network, or any other network with a prefix of 24 or more, it is easy to determine the network address and broadcast address by simply adding up the number of hosts per subnet, butin general writing out the addresses in binary format is the way to go. For example, to determine the network address of the subnet in which the IP address with subnet mask (prefix 21) resides:

    Subnet A 00001010.00000100.11011100.00100100
    Subnet B 11111111.11111111.11111000.00000000
    ------------------------ -----------------------------------------------------
    Network Address: 00001010.00000100.11011000.00000000
    The above shows the binary AND process. Only if the bit is 1 in the IP address “and” in the subnet mask, it will be 1 in the network address. All you need to do next is translate the binary network address back to decimal, which is We basically took the first 21 bits of the IP address, basically discarding the hosts portion of the address, which leaves us with just the network portion, which padded with zeros is the network address. To determine the broadcast address all you need to do is set all host bits to ‘zero’. For example:

    Network Address: 00001010.00000100.11011000.00000000
    Broadcast Address: 00001010.00000100.11011111.11111111
    Next, apply basic binary math to translate the binary broadcast address to its decimal format, which is

    The valid host range for a subnet consists of all addresses between the network address and the broadcast address.


    VLSM stands for Variable Length Subnet Masking and allows you to use the available address space more efficiently. For example, if you divide a class C network into two subnets, you can still divide one of the two subnets into additional subnets. An example network using VLSM is depicted below: content/attachments/1545-subnettingqestionsdiagram3vlsm.png.html
    In this example network, a Class C network is divided into variable length subnets. Subnet A uses a prefix of /25, which basically divides the network into two subnets (a class C uses 24 bits for the network portion by default, so 1 additional bit is used for subnets, which allows for 2 different subnets).

    Subnet A: ranges from –, allowing for 126 hosts in total (after subtracting the network address and broadcast address for the subnet). Without VLSM that would automatically leave us with – for the second subnet. However, by assigning a higher prefix/mask to the second subnet we can divide it further into smaller subnets.

    Subnet B: ranges from –, allowing for 64 addresses, minus two for the network ( ) and broadcast address ( leaves 62 valid host addresses.

    That still gives us –, which could be used for another subnet with 62 hosts, but can also be divided into smaller subnets yet again:
    Subnet C: ranges from –, allowing for 30 hosts. To summarize, we end up with the following subnets:

    Subnet Network Address Hosts
    Subnet A 126
    Subnet B 62
    Subnet C 30
    Unassigned 30


    Supernetting is more or less the opposite of subnetting but instead of dividing networks into subnets, networks can be combined in to a larger supernet. In practice this comes down simply to using a smaller prefix/mask than the default for a particular class. For example, a class C network with a prefix of /23 (mask: would allow for twice as many hosts as a regular “classful” class C network using the default mask of The supernet for example ranges from - (the first being the network address, the last being the broadcast address and everything in between, 510 addresses, for hosts).

    IP Subnetting Practice Test (CCNA)
    TechExams.net IP Subnet Calculator for Windows

    If you have any questions regarding this TechNotes post them in the comments below or in our CCNA forums.

    Members-only Printer-friendly version
    Comments 18 Comments
    1. ajmalkhanmsc's Avatar
      ajmalkhanmsc -
      great work...
    1. RoyalTech's Avatar
      RoyalTech -
      Webmaster, you use the subnet /25 as an example. It's my interpretation that you cannot have a single character network ID extension forcing you to start subnetting at /26 for a standard class C address. Am I misinterpreting something here?
    1. lovefromindia's Avatar
      lovefromindia -
      webmaster this calculator is simply gr8 i found many but this is the best of the best thankyou
    1. LiraCCNA's Avatar
      LiraCCNA -
      luv it !!!
    1. belkassem's Avatar
      belkassem -
      Thanks helpfull
    1. shyamnagotra's Avatar
      shyamnagotra -
      thnx really helpful for me
    1. mohamedshajid's Avatar
      mohamedshajid -
      Webmaster you helped me a lot brother, Fine i missed ma first IP Subnetting class Now i've got this
    1. indshiva's Avatar
      indshiva -
      nice topic and better understand
    1. sadakat040's Avatar
      sadakat040 -
      its awesome notes
    1. Node Man's Avatar
      Node Man -
      great notes
    1. MrB1ll's Avatar
      MrB1ll -
      In the example shouldn't it be set the host bits to "one" instead of "....To determine the broadcast address all you need to do is set all host bits to ‘zero’."
    1. amariano1989's Avatar
      amariano1989 -
      This software, a calculator for getting accurate I is very good but also, don't forget to understand the basics in subnetting because if you understand the basic in subnetting, you may also easily understand what the IP Calculator results for every IP's.
    1. jerrizm's Avatar
      jerrizm -
      very helpful!! nice topic
    1. Judea's Avatar
      Judea -
      God Bless you richly. You're a big big blessing to my life. Thank you so much. Ori re ko ni buru o.
    1. brethz's Avatar
      brethz -
      tnx for this nice input..Job well done.
    1. Sameddy's Avatar
      Sameddy -
      Just want to say thanks.
      This is of great help for my CCNA class.
    1. ChappySinclair's Avatar
      ChappySinclair -
      This is fantastic, just started studying for my CCNA and this is a great help!
    1. GHOSTRIDER2016's Avatar
      GHOSTRIDER2016 -
      This is a good article thanks Webmaster
  • ISI