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   = 01010001.10001010.11011011.00101101
Subnet mask          = 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:

                       = 01010001.10001010.11011011.00101101
                     = 11111111.11111111.11111111.11111000
                          AND -----------------------------------------------------
                                                01010001.10001010.11011011.00101000 =

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.

                     = 11111111.11111111.11111111.11111000 subnet mask
                             = 00000000.00000000.00000000.00000111 all bits flipped
                       = 01010001.10001010.11011011.00101101
                             = 00000000.00000000.00000000.00000111 complement of mask
                           OR -----------------------------------------------------
                                                01010001.10001010.11011011.00101111 =

Using this calculation you can determine: