Ken’s Network Administration Information

Subnetting

Introduction

Subnetting scares a lot of people. There's no need to let it frighten you. If you're comfortable with the binary number system, it's just a bunch of ones and zeros, then you can understand subnetting. Here is a procedure that I learned at CNM.

Example Problem

29 . 99 . 37 . 88   /17

We are given the above ip address and CIDR. Our task is to calculate several pieces of information from it.

The Procedure

We know this is a class A and we know the default mask for a class A is 255 . 0 . 0 . 0

First, write out your binary charts for easy reference while you work on the problem.

 

  1. Find the subnet mask in binary and decimal.
  2. First, write out the mask using 255 for the default portion, 1’s for all the borrowed bits and zeros for all the host bits.

    255 . 1 1 1 1 1 1 1 1 . 1 0 0 0 0 0 0 0 . 0
    n . s s s s s s s s . s h h h h h h h . h

    Converting from binary to decimal, the mask is 255.255.128.0. The magic number is 128.

     

  3. Find the subnetwork number.
  4. The magic number is in the third octet so we need to convert that octet in the IP, 37, to decimal. Write out your conversion table then do the conversion.

    128 64 32 16 8 4 2 1

    37 in decimal = 0 0 1 0 0 1 0 1 in binary. Now perform a bit-wise AND with the binary number you just found and the binary version of the third octet in the mask.

    1 0 0 0 0 0 0 0
    0 0 1 0 0 1 0 1
    ---------------
    0 0 0 0 0 0 0 0

    That gives us the network number for the given IP and mask.

    29 . 99 . 0 . 0

    Note that we simply brought down the 99 from the second octet because that octet in the mask was all ones. This example can be extra confusing because the borrowed bits cross an octet boundary. That’s why I used it here.

     

  5. Find the first usable host address.
  6. The first host address is always the subnetwork number plus 1.

    29 . 99 . 0 . 1

     

  7. Find the next subnetwork number.
  8. This is always the current network number plus the magic number. In this case it is:

    29 . 99 . 128 . 0

    Note that the 128 is in the 3rd octet because that’s where the magic number is.

     

  9. Find the broadcast address.
  10. The broadcast address is always the next subnetwork number minus one and is always odd.

    29 . 99 . 127 . 255

     

  11. Find the last usable host address.
  12. The last host address is always the BC minus one and is always even.

    29 . 99 . 127 . 254

     

  13. Find the total number of IPs with this address/mask.
  14. The total number of bits is 32. The mask is using 17. That leaves 15 for the host portion. Now raise 2 to the 15th power to get the total number of IPs.

    215 = 32768

     

  15. Find the total number of valid host addresses.
  16. This is always the total number of IPs minus 2.

    32768 - 2 = 32766

     

  17. Find the total number of subnetworks.
  18. Take the difference between the default mask, /8, and this mask, /17, to get 9. Now raise 2 to the power of 9.

    29 = 512

     

  19. Find the first two subnetwork addresses.
  20. The first subnetwork number will have all the borrowed bits set to zero *and* all the host bits set to zero. Looking back at the binary mask in #1 above, we can see that if we set all the borrowed bits to zero we get the following:

    First subnetwork number:

    29 . 0 . 0 . 0 (Magic# = 128; 128 x 1 — 128 = 0)

    Now we add the magic number to that, in the correct octet, to get the second subnetwork number:

    29 . 0 . 128 . 0 (aka: Magic number x 1)

    And so on… 

    29 . 1 . 0 . 0
    29 . 1 . 128 . 0
    29 . 2 . 0 . 0

     

  21. Find the last two subnetwork addresses.
  22. Here’s a trick. The very last subnetwork number will be the mask! Here’s how that works. Keep the first octet of the IP because it’s a class A. If it were a class B, you would keep the first two and for a class C, the first three. Then fill in the rest of the octets from the mask.

    Last subnetwork address: 

    29 . 255 . 128 . 0

    Next to last subnetwork: 

    29 . 255 . 0 . 0

    And so on… 

    29 . 254 . 128 . 0
    29 . 254 . 0 . 0
    29 . 253 . 128 . 0

     

In summary.. .

Given IP address and CIDR: 29 . 99 . 37 . 88   /17
Subnet mask: 255 . 255 . 128 . 0
Subnetwork address: 29 . 99 . 0 . 0
Valid host address range: 29.99.0.1 to 29.99.127.254
Broadcast address: 29 . 99 . 127 . 255
Total number of IPs: 32768
Total number of valid host addresses: 32766
Subnets: 29.0.0.0 to 29.255.128.0, incrementing by 128
Total number of subnetworks: 512

 

Next:

Now, let's apply all of this to a practical subnetting problem.