Jump to content
  • Advertisement
Sign in to follow this  
Fl4sh

How does subnetting work?

This topic is 2868 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!