Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am not sure if this is the right place to make this question but I thought this is one of the most appropriate SE's site to make a question on networking. Please move it to other more appropriate sites. Thanks.

So suppose I have a block of IPv4 addresses and one of the hosts address is 182.44.82.16/26. Is it possible for me to find the first and last address of this block of address?

I am thinking like:

182.44.82.16 is 182.44.82.(0001 0000) where the (0001 0000) is the binary for 16.

Since the mask is /26, I thought I could do this:

IP:   182.44.82.(0001 0000)
Mask: 182.44.82.(1111 1000)

And then this means I left with only the last 3 bits for the IP addresses, which makes the first address going to be 182.44.82.16 and the last address 182.44.82.23. But this doesn't look quite right. How can I calculate the first and last addresses of this block of addresses?

share|improve this question

3 Answers 3

up vote 1 down vote accepted

/26 means 26 bits for the subnet. At 8 bits per byte you get 24 for the first three bytes, and two for the last. It means your last byte will be of the form (nnhh hhhh), where n is a subnet bit and h a host bit. 16 is indeed (0001 0000), so you get (00xx xxxx).

Thus the network address is (00|00 0000) -> .0, the broadcast is (00|11 1111) -> .63, and the first and last useable addresses are .1 and .62.

share|improve this answer

IPv4 addresses are 32-bit unsigned INTs.

Since both the address and netmask can be expressed as a 32-bit unsigned INT, and they are intimately related, this is easy:

first = (addr && netmask)
last = (addr && netmask) + !netmask
share|improve this answer
    
Is the ! sign flipping the bits? Eg: !(101101) = 010010, is this right? –  xenon Nov 4 '11 at 13:09
    
Correct. I was using C semantics, where ! means NOT. It is equivalent to (MAXINT XOR netmask), which may make it more clear for you. –  adaptr Nov 4 '11 at 13:11

Subnet Calculator might work, http://www.subnet-calculator.com/. Assuming the network class is class 'B' you get 182.44.82.0 - 182.44.82.63

share|improve this answer
    
Why assume ? He stated the CIDR netmask is /26. Really, "classes" are not exactly relevant anymore. –  adaptr Nov 4 '11 at 13:20

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.