views:

186

answers:

4

Hi all,

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!

+7  A: 

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.

Konamiman
The broadcast address doesn't have to be all-ones address. Although it almost always is, and perhaps that has been standardized. On Linux, the broadcast address is configurable separately from the netmask.
Peter Cordes
Maybe I'm confused but maybe you are referring to the *multicast* address (I'm not sure, anyway).
Konamiman
All 0's and all 1's for the broadcast address have both been allowed in the past. All 1's is now more standard, and I believe there is a MIB variable that controls 0's or 1's. I am fairly sure that all 0's as an address is reserved to avoid conflict with the old standard. And of course in a /31 or /32 network there is no broadcast address!
Tony van der Peet
Oh, and multicast is a special type of IP address that has its own reserved address space.
Tony van der Peet
Thanks for the clear response!
Jasie
Hang on! You've given results for a mask of /20!
Tony van der Peet
A: 

In a word, yes.

http://en.wikipedia.org/wiki/IPv4%5Fsubnetting%5Freference

http://en.wikipedia.org/wiki/Classless%5FInter-Domain%5FRouting

http://www.faqs.org/rfcs/rfc1519.html

Peter Cordes
What did I get voted down for? For saying that the questioner had it right, even though I didn't check his numbers? I noticed that he inverted the bitmask from the usual convention, but that's the right thing to do to find the network address. That's why I linked to some docs on the notation.
Peter Cordes
I didn't vote you down. I haven't checked the references, but they all look useful, so guess what, I'm going to vote you up.
Tony van der Peet
With my last vote of the day no less.
Tony van der Peet
+2  A: 

@Konamiman - your answer is pretty much spot on (+1), but I couldn't avoid answering because of the strange stuff in the question.

First of all, I would like to highlight that the OP got the 12 bits inverted, /12 means 12 bits of 1's one the left, not 12 bits of zeroes on the right.

Second, 171.58.0.0/12 in binary is 10101011.00111010.00000000.00000000 (as the OP states) with a mask of 11111111.11110000.00000000.00000000, which means that you have non zero bits in the host address part of the address. As far as I know, this is not the way to express a block of addresses, even though it is a valid single address in that subnet.

More sensibly, you would express this as 171.48.0.0/12 (is this a typo in the question?), which means that the host part is all zeroes. The smallest valid netmask for 171.58.0.0 would be /15.

EDIT: Take a look at this IP addressing guide. It's a bit out of date since it refers to class A, B, C, but is a useful cheat sheet for netmasks.

Tony van der Peet
Ooops, I didn't notice the bit inversion. I just relied on the sample binary representation he provided.
Konamiman
Thanks for the clarification. I had non-zero bits in the host address part of the address since the example was contrived...I just made up numbers :)
Jasie
What a hoot! Neither of us can see the wood for the trees.
Tony van der Peet
A: 

Assuming that this is based upon CIDR, maybe`

Mask:255.240.0.0     Host/Net - 1048574
Network          Broadcast
171.48.0.0       171.63.255.255
dbasnett