Thursday, January 13, 2011

How to find IP addresses and subnet number

When you know IP address and mask number, you sometimes want to know subnet number, subnet broadcast address and range of valid IP addresses. In common ways, you can find these by convert the IP address with mask number to binary and perform boolean AND but that takes too much time. So let see how to find these answers in a short time.

Before I start, let see the general table which will used to describe IP address. In each column will be the IP address that separate by octet, dot-notation (x.x.x.x). In each row is the IP address.

Generic Subnet Table

Octet 1 2 3 4
Address



Subnet number



First Address



Broadcast Address



Last Address



Let’s start

I divide into 2 categories which depend on subnet mask:

  1. Do Maths with easy masks
    For the masks that contain only 255s and 0s. There are three masks which are 255.0.0.0, 255.255.0.0 and 255.255.255.0.
    I guess many people know this already, but l will explain a little bit to revise for someone.
    1. Find the subnet number
      • Copy first octet (mask 255.0.0.0), first two octets (mask 255.255.0.0) or first three octets (mask 255.255.255.0) from IP address
      • Put 0s in the remaining octets
    2. Find the broadcast the address
      • Copy first octet (mask 255.0.0.0), first two octets (mask 255.255.0.0) or first three octets (mask 255.255.255.0) from IP address. This is the same in ‘Find the subnet number’, step 1
      • Put 255s in the remaining octets
    3. Find range of valid IP addresses
      • To find the first valid IP address, copy the subnet number and add 1 to the fourth octet
      • To find the last valid IP address, copy the broadcast address and subtract 1 to the fourth octet
    4. Example
      • Mask 255.0.0.0
        Octet 1 2 3 4
        Address 10 110 140 1
        Subnet number 10 0 0 0
        First Address 10 0 0 1
        Broadcast Address 10 255 255 255
        Last Address 10 255 255 254
      • Mask 255.255.0.0
        Octet 1 2 3 4
        Address 10 110 140 1
        Subnet number 10 110 0 0
        First Address 10 110 0 1
        Broadcast Address 10 110 255 255
        Last Address 10 110 255 254
      • Mask 255.255.255.0
        Octet 1 2 3 4
        Address 10 110 140 1
        Subnet number 10 110 140 0
        First Address 10 110 140 1
        Broadcast Address 10 110 140 255
        Last Address 10 110 140 254
  2. Do Maths with difficult masks
    In this case, mostpeople find it’s difficult to calculate and some has to do by binary math which is time consuming. Let see the way to figure out in few seconds.
    1. Find the subnet number
      • I will define the column that contain the difficult number(not 255s and 0s) as the interesting column. For any octets fully to the left of the interesting column, copy value(s) from the original IP Address into all addresses(subnet number, first-last address and broadcast address).
        Octet 1 2 3 4
        Address 130 4 102 1
        Mask 255 255 252 0
        Subnet number 130 4

        First Address 130 4

        Broadcast Address 130 4

        Last Address 130 4

      • For any octets fully to the right of the interesting column, put 0s in the subnet number.
        Octet 1 2 3 4
        Address 130 4 102 1
        Mask 255 255 252 0
        Subnet number 130 4
        0
        First Address 130 4

        Broadcast Address 130 4

        Last Address 130 4

      • Now the tricky part, find a ‘magic number’ which is 256 minus mask’s interesting octet. In this example, it is 256 – 252 = 4.
      • Find the multiple of the magic number that is closest to, but not greater than the the interesting octet of original IP address. For this case, it is 100 (4*25) which also not greater than 102.
      • Put the result from previous step in subnet number of the interesting column.
        Octet 1 2 3 4
        Address 130 4 102 1
        Mask 255 255 252 0
        Subnet number 130 4 100 0
        First Address 130 4

        Broadcast Address 130 4

        Last Address 130 4

    2. Find the broadcast address
      • For any octets fully to the right of the interesting column, put 255s in the broadcast address. The left part should be filled already in Find subnet number, the upper.
      • Again, use the magic number. By adding the magic number to the interesting octet of subnet number and subtract 1. In this example, the magic number is 256 – 252 = 4, 100 + 4 – 1 = 103.
      • Put the result from previous step in broadcast number of the interesting column.
        Octet 1 2 3 4
        Address 130 4 102 1
        Mask 255 255 252 0
        Subnet number 130 4 100 0
        First Address 130 4

        Broadcast Address 130 4 103 255
        Last Address 130 4

    3. Find range of valid IP addresses
      The way used to find the first and last IP addresses are the same in easy mask.
      • To find the first valid IP address, copy the subnet number and add 1 to the fourth octet
      • To find the last valid IP address, copy the broadcast address and subtract 1 to the fourth octet
        Octet 1 2 3 4
        Address 130 4 102 1
        Mask 255 255 252 0
        Subnet number 130 4 100 0
        First Address 130 4 100 1
        Broadcast Address 130 4 103 255
        Last Address 130 4 103 254

No comments: