cancel
Showing results for
Did you mean:
cancel
Announcements

3183
Views
0
4
Replies
Beginner

## Determining whether two addresses are on the same subnet formula?

Hello Everyone,

What is the formula or mathimatical operation to determine whether two addresses are on the same subnet or not?

I know that I can use AND operation to do this but this is time consuming, also I know the formula in MS Press book which is :

f1 = [K1 / (256-d)] - any reminder

f2 = [K2 / (256-d)] - any reminder

Where K1 and K2 are the respective value of the octet in each IP address whose position corresponds to d

and "d" is the modrange value octet in the subnet mask.

didn't get it right

lets take this example to understand:

I need to determine whether these rwo IP addresses are in the same subnet

192.168.0.180     180 is K1

192.168.0.192     192 is K2

with net massk of 255.255.255.224     224 is d

using this information we will see

f1 = [180 / (256-224)] = 180 / 32 = 5.625

f2 = [192 / (256-224)] = 180 / 32 = 6

f1 is not equal to f2 and so they are not in the same subnet!

Well this formula works sometimes but others not!

now lets do the traditional way of determining whether these rwo IP addresses are in the same subnet:

Binary         : 11111111     11111111     11111111     11110000

The increment value is 16 therefore:

192.168.0.16    192.168.0.31

192.168.0.32    192.168.0.47

192.168.0.48    192.168.0.63

192.168.0.64    192.168.0.79

192.168.0.80    192.168.0.95

192.168.0.96    192.168.0.111

192.168.0.112   192.168.0.127

192.168.0.128   192.168.0.143

192.168.0.144   192.168.0.159

192.168.0.160   192.168.0.175

192.168.0.176   192.168.0.191          here is the first IP Subnet  ( 180 )

192.168.0.192   192.168.0.207          here is the secons IP Subnet and it is the network ID itself ( 192 )

192.168.0.208   192.168.0.223

192.168.0.224   192.168.0.239

Now we know that they are not in the same subnet!

The Question IS, How can I jump directly to the desired range without writing all of these ranges to get to the desired range ?????

I saw a vedio before and the guy said that I can use the number and make it power of 10 to jump directly to the Range ??? but I can't find the Video

Does anyone has idea how to do this

Thank you very much

Everyone's tags (9)
1 ACCEPTED SOLUTION

Accepted Solutions
Collaborator

## Re: Determining whether two addresses are on the same subnet for

wouldn't this give you what you want:

if the devision has a rest (module not eqals 0)               # e.g. 180/32 = 5.625

take just the integer and multiply it with [256 - d]             # 5 * 32 = 160

it gives you the network directly:        192.168.0.160

but you made a little mistake - just a bit-swap..

is

Binary         : 11111111     11111111     11111111     11100000

and not

Binary         : 11111111     11111111     11111111     11110000

therefore, the increment value is 32 not 16 - and that is what you get when you subtract 224 from 256:

256 - 224  = 32     (the number of addresses for each subnet)

if the modulo equals 0 you have the first IP of the network directly;

4 REPLIES 4
Collaborator

## Re: Determining whether two addresses are on the same subnet for

wouldn't this give you what you want:

if the devision has a rest (module not eqals 0)               # e.g. 180/32 = 5.625

take just the integer and multiply it with [256 - d]             # 5 * 32 = 160

it gives you the network directly:        192.168.0.160

but you made a little mistake - just a bit-swap..

is

Binary         : 11111111     11111111     11111111     11100000

and not

Binary         : 11111111     11111111     11111111     11110000

therefore, the increment value is 32 not 16 - and that is what you get when you subtract 224 from 256:

256 - 224  = 32     (the number of addresses for each subnet)

if the modulo equals 0 you have the first IP of the network directly;

Beginner

## Determining whether two addresses are on the same subnet formula

OMG it's not a small mistake I did, it's BIG which could ruin the whole question lol

Very good Martin it is easier now for me

Thanks

Highlighted
Hall of Fame Guru

## Determining whether two addresses are on the same subnet formula

In addition to Martin's correct answer regarding appllication of the formula you cited, you may also want to consider a tool that you can run for this. Solarwinds offers a free (ad-supported) version of their Subnet Calculator that you can download to your desktop. Here is a link to it. It's also included (without ads) in their paid Engineer's Toolset product.

Of course there are also web sites with tables and such.

Beginner

## Determining whether two addresses are on the same subnet formula

Thanks a lot mklemovitch

The software is awesome but I needed this information for the Cisco exam and Microsoft infrastructure exam too, therefore the calculator would be useful for me only as a helper to chk my results but it's very helpful.