WORKING OUT IPV4 LAN ADDRESS RANGE

Introduction

There are occasions when you may need to work out the first and last IP addresses in a network given only an IP address in that network and its subnet mask. This is useful when calculating the number of addresses in the network or when you need to process each IP address separately. The following example shows how the calculation works. First, choose an IP address in the range and the subnet mask.

Current network address       81.138.219.45   = 01010001.10001010.11011011.00101101
Subnet mask                   255.255.255.248 = 11111111.11111111.11111111.11111000

To find the first address, which is also the network address, you bit-wise AND the given IP address and the subnet mask:


                              81.138.219.45   = 01010001.10001010.11011011.00101101
                              255.255.255.248 = 11111111.11111111.11111111.11111000
                          AND -----------------------------------------------------
                                                01010001.10001010.11011011.00101000 = 81.138.219.40

To find the last address, which is also the broadcast address, you OR the given IP address with the complement of the subnet mask. The complement of the mask is obtained by flipping each bit.

                              255.255.255.248 = 11111111.11111111.11111111.11111000 subnet mask
                              0.0.0.7         = 00000000.00000000.00000000.00000111 all bits flipped
                              
                              81.138.219.45   = 01010001.10001010.11011011.00101101
                              0.0.0.7         = 00000000.00000000.00000000.00000111 complement of mask
                           OR -----------------------------------------------------
                                                01010001.10001010.11011011.00101111 = 81.138.219.47

Using this calculation you can determine: