Tech Support Guy banner
Status
Not open for further replies.

IP and Subnet mask, the link?

1K views 8 replies 4 participants last post by  Alastair_M 
#1 ·
A question of theory: if I have the IP address of a PC, and I want to ping another PC of which I have the IP address but I am not sure if it is within my same network, what is the method?
I have heard that I have to do an END operation between my IP in binary and my subnet mask. The result will tell me if the PC I'm pinging, belongs to my network or not.
Now, what is this result? How can I understand from this result if that PC is out or in my network?
thank you
 
#2 ·
An END operation? Never heard of it. What you want is an AND operation.

First off, it must be a given that the network is in a correctly working state.

Then you need to do two AND operations actually. One for your IP address against your subnet mask, another for the destination IP address and your subnet mask (or the destination's subnet mask if you know it, but either will work). If the two results are the same, the two addresses are in the same subnet.

You could also short circuit the operation, if the two masks are different then the addresses will be in different subnets.

If the network is not given to be working, there are all kinds of examples that will give ambiguous answers when the subnet masks for the two networks are inconsistent.

-Scott
 
#3 ·
Hi Number

You could try this to save a headache. Take the subnet portion of the address and as an example i'll use .224. Take the subnet portion figure away from 256 (its always 256) The result is 32. The subnets on you rnetwork will start at multiples of 32. These are the network addresses of your subnets. If your machine and the one you are pinging both come into one group of addresses you are on the same subnet. A bit confusing? Here's an example:

IP address: 192.168.10.22
Subnet Mask 255.255.255.248

248 is the subnet portion. Take it from 256 as explained. The result is 8. Your first usable subnet is 192.168.0.8 The next is 16 then 24 then 36 etc etc till you reach 248. If you are machine number 192.168.0.18 and you are pinging 192.168.0.21 it is in the same subnet. If it is machine number 25 it is in another subnet.

Try this:

http://www.learntosubnet.com/
 
#4 ·
5mi11er , thank you, but by doing an AND operation say from 11100011.10000000 and 11111111.11111111 wouldnt the result be always the first one?

Hermes, I don't understand what you mean with first usable subnet, isn't 192.168.0.8 an IP address of an host?
Also, will the 3th number be always zero? (192.168.0.8)

By looking 192.168.0.18 and 192.168.0.21 how can you tell that they are in the same subnet?
 
#5 ·
Hi Number

I thought about this when I first started typing and whether explaining it would raise more questions than it answered.

If you subnet, you use station addresses as network numbers. This is a downside of subnetting, in that you lose usable station addresses. The first and last addresses in a subnet are unusable as they are the network and broadcast addresses. 192.168.0.8 would be the network address of this subnet and 192.168.0.15 the broadcast.

The third number will not always be zero but the address I used is commonly used to explain IP addressing and subnetting.

In the example I used, the subnet addresses started 192.168.0.8 then went in multiples of 8. If your addresses are both within one of these groups (18 and 21 are both in the subnet starting 192.168.0.16 and ending 192.168.0.23) they are in the same subnet.

I have to go, let me know if you want an in depth explanation.
 
#6 ·
Yes, in your example, using only two octets, you will always get back what you started with. That's because your example subnet is all ones (aka 255 aka 0xff). If we use a better real world example, I think you'll get it.
Code:
IP #1      145.236.54.12   = 0x91.0xEC.0x36. 0000 1100
Mask #1  255.255.255.224   = 0xFF.0xFF.0XFF. 1110 0000

IP #2      145.236.54.45   = 0x91.0xEC.0x36. 0010 1101
Mask #2: unknown
To save some space, I've converted the first three octets into Hex, as they really don't matter anyway in this particular example.
Code:
ANDing IP #1 and Mask #1, you'll get 0x91.0xEC.0x36.0000 0000
ANDing IP #2 and Mask #1, you'll get 0x91.0xEC.0x36.0010 0000
That one lonely little one in the 3rd from left spot of the last octet is the only thing different from the two results, but that's all you need to say that those two IP addresses are NOT in the same subnet.

-Scott
 
#7 ·
Hi guys,

I hope you don't mind if I offer a slightly different perspective that might help.

The idea that's underlying all of this is that a 32-bit IP address can be divided up into a network ID and a host ID.

The subnet mask specifies which bits in the IP address are part of the network ID and which bits are part of the host ID. A 1 in a given position in the subnet mask means that the equivalent bit in the IP address is part of the network ID. A 0 in the subnet mask means that the equivalent bit in the IP address is part of the host ID.

For example, a subnet mask of 255.255.255.0 means that the leftmost 24 bits of the IP address make up the network ID and the rightmost 8 bits make up the host ID. (255 in decimal notation converts to 11111111 in binary, so the subnet mask of 255.255.255.0 converts to a string of twenty-four 1's followed by eight 0's.)

In 5miller's example, the subnet mask consists of a string of twenty-seven 1's followed by five 0's, so the network ID consists of the leftmost twenty-seven bits of the IP address. Therefore, if the leftmost twenty-seven bits of the two IP addresses match then the addresses are in the same network.

Performing a binary AND operation between an IP address and a subnet mask basically "keeps" the IP address bits in the positions where the subnet mask bit is a 1 and "throws away" the IP address bits where the subnet mask bit is a 0. The AND operation therefore "extracts" the network ID from the IP address.

I find it easier to think of the 1's in the subnet mask "pointing to" the bits in the IP address that make up the network ID.

Alastair
 
Status
Not open for further replies.
You have insufficient privileges to reply here.
Top