Sign in to follow this  
Fl4sh

How does subnetting work?

Recommended Posts

I'm trying to understand exactly how this crap works. So if you have an ip address like:

160.55.0.0 and the subnet mask is 255.255.0.0

if you change the subnet mask to 255.255.240.0 to accommodate the requirement of 10 subnets, what do you have to do to the ip address because bitwise AND will return 0 between 240.0 and 0.0.

And uhh...this might not be the most appropriate place for this, I dunno. ;o

Share this post


Link to post
Share on other sites
It's relatively straight forward. These numbers can be used to determine if a particular IP address is in the subnet or not. The rule is

if ((IP_address & 255.255.0.0) == 160.55.0.0) {
// Yes, it's in the subnet
}
else {
// Not in the subnet
}


In other words, only IP addresses of the form 160.55.xxx.yyy are in the subnet.

If you change the mask to 255.255.240.0, let's write it in binary to see what it really means: 11111111.11111111.11110000.00000000. So now IP addresses have to have the form 160.55.xxx.yyy, but with xxx between 0 and 15.

Do the bitwise AND by hand with several examples to see for yourself how it works.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this