Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

ip address math

Posted on 2007-11-26
11
Medium Priority
?
725 Views
Last Modified: 2010-08-05
I'm trying to figure out how many addresses fit into a range.  For example, how many addresses are in the range 128.100.0.0 - 128.100.255.255?  Is there a formula I can use to figure out the number of possible addresses from range1 - range 2?  
0
Comment
Question by:npinfotech
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +3
11 Comments
 
LVL 7

Expert Comment

by:UrosVidojevic
ID: 20350549
A.B.C.D -> P.Q.R.S

(P*256^3 + Q*256^2 + R*256 + S) - (A*256^3 + B*256^2 + C*256 + D) + 1
0
 
LVL 46

Expert Comment

by:Kent Olsen
ID: 20350558
Hi npinfotech,

Sure.  :)

Think of the IP address for exactly what it is.  4 bytes.

128.100.0.0 is 0x80 64 00 00
128.100.255.255 is 0x80 64 FF FF

Just convert the IP addreses to integers in hex and subtract them.  Convert the values to decimal before or after the subtraction to get the number of values in the range.

In your example, there are 0x00 00 FF FF values in the range (plus 1) for 65,536 values.
 


Good Luck,
Kent
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 20350564
The subnet mask for that range is 0x0000FFFF, so there are 2^16 (= 65536) addresses in the range.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 53

Expert Comment

by:Infinity08
ID: 20350574
>> The subnet mask for that range is 0x0000FFFF

I should have said 0xFFFF0000 of course ;)
0
 
LVL 71

Expert Comment

by:Chris Dent
ID: 20350577

Hey :)

There are a couple of ways.

Number of Hosts per Subnet = 2^(Number of Host Bits) - 2

In the example above you would have a mask of 255.255.0.0. That means we have 16 bits available to Hosts (32 bits - 16 masked bits).

That means we can have this many addresses for hosts:

(2^16) - 2 = 65536 - 2 = 655534

Where the 2 is for the Network and Broadcast address which are unusable by hosts.

HTH

Chris
0
 
LVL 22

Expert Comment

by:NovaDenizen
ID: 20350594
If you know your binary arithmetic and understand netmasks, then the answer should be pretty easy.

For your example, the third octet can have the values 0-255, and the fourth is the same.  There are 256*256 different combinations of these values, or 65536.  If the netmask is such that 128.100.0.0 is at the beginning of the subnet range, then subtract 1.  If the netmask is such that 128.100.255.255 is at the end of the subnet range, subtract 1.

So, if you're calculating the number of valid addresses in the 128.100.0.0/16 subnet, there are 65534 valid IP addresses.
0
 
LVL 7

Accepted Solution

by:
UrosVidojevic earned 2000 total points
ID: 20350598
In this case:

128.100.0.0 -> 128.100.255.255

(128*256^3 + 100*256^2 + 255*256 + 255) - (128*256^3 + 100*256^2 + 0*255 + 0)
= 65536,

Pay attention that, in this subnet 128.100.0.0 and 128.100.255.255 can be used...
0
 
LVL 7

Expert Comment

by:UrosVidojevic
ID: 20350615
I should have said can't be used...
0
 
LVL 8

Author Closing Comment

by:npinfotech
ID: 31410993
Great answers guys, but Uros' answer was more of what I was looking for.  
0
 
LVL 8

Author Comment

by:npinfotech
ID: 20351113
Thanks to everyone for responding to the post!  While all the answers were good, Uros had the method I was looking for.
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 20351431
>> Uros had the method I was looking for.

It's more complicated than the other suggested ways though ...
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you try to share a printer , you may receive one of the following error messages. Error message when you use the Add Printer Wizard to share a printer: Windows could not share your printer. Operation could not be completed (Error 0x000006…
Sometimes clients can lose connectivity with the Lotus Notes Domino Server, but there's not always an obvious answer as to why it happens.   Read this article to follow one of the first experiences I had with Lotus Notes on a client's machine, my…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

609 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question