ip-addresslongest-prefix

How to interpret an IP address block?


If I have a block of private IP addresses such as 171.58.0.0/12, does this mean that I essentially bitwise AND the 32-bit version of 171.58.0.0 with 32 bits of 1's, the last 12 of which are 0'd out, to get the longest prefix of acceptable private IP addresses in that range?

10101011.00111010.00000000.00000000 (171.58.0.0) AND
11111111.11111111.11110000.00000000 (12 bit mask?)

=

10101011.00111010.00000000.00000000 (Longest Prefix of Private IP addresses)

to get the prefix acceptable private IP addresses?

Thanks!


Solution

  • You make a 32 bit number which has the higher 12 bits set to one, then AND it to the given IP address, and you get the network address. The remaining bits are available for host addresses, except the reserved numbers of all zeros (the network address itself) and all ones (the broadcast address). In your case it would be:

    171.58.0.0 = network
    171.58.0.1 to 171.58.15.254 = hosts
    171.58.15.255 = broadcast
    

    EDIT. See Tony van der Peet's answer since it adds valuable information to my answer.