CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2006
    Posts
    99

    Question can't understand ipv4 and subnet mask

    hello guys,

    i can't understand the ip address and the subnet mask.


    my first question is:

    is the "subnet mask" only for the subnet?

    given a public ip, and a subnet mask, can you tell which machine the ip is pointing to inside the a subnet?

    for example, if i visit this http://whatismyipaddress.com/, it will tell me that my ip address is

    234.247.121.220

    and from my windows 7 settings, i know that my subnet mask is 255.255.255.0. so that means, i am the number 220 machine inside the subnet?

    BTW, I'm using the wireless of my school.


    or, the subnet mask is only for the subnet , it has nothing to do with my public ip?

    from my windows setting, my ipv4 address is 192.168.1.35 my subnet mask is 255.255.255.0, so really i am the number 35 machine of the subnet??




    the second question is, if the subnet mask is only for the subnet, then why people say that ip address can be divided into class A, B, C and D??

    does a public ip also fall into one of the four classes?

    if public ips also have different classes, then the overall ip addresses cannot be 2^32, because if you look at the class A ips, there are only 256 ips in total.




    my third question is, if i want to build a home wireless network and i have two machines and an ap. why should i use the subnet mask 255.255.255.0?

    why can't i use 255.0.0.0? and who invented 192.168.x.x ??? why not something else?

    can my ipv4 address be set to 175.0.0.2 and use 255.0.0.0 as the mask?



    if i were the inventor of the whole IP thing, i would give each public machine or a router an unique ip, but within each subnet, i would use integers, machine 1, machine 2, machine 3 ....

    why bother with subnet maskes?

  2. #2
    Join Date
    Oct 2010
    Posts
    68

    Re: can't understand ipv4 and subnet mask

    First, make sure you understand the difference between a Public IP Address and Local IP Address. Because of a wonderful thing called Network Address Translation and Routing you can purchase only one Public IP address for a company and have as many systems behind that as you want. Your IP address that you see on that website is the public interface of the network you are on. Your local IP address is the 192.168.1.35 that is configured on your machine. None of this has anything to do with your subnet mask.

    Your subnet mask is simply a way of defining the limits for a given network. Let's use an example Subnet Mask of 255.255.255.0 This means that the first three octets of the IP Addresses in your network will be the 'Net ID' and that last one will be the unique 'Host ID'. So with an IP Address of 192.168.0.1 your Net ID is shown in red(all computers on the network will have these three octets) and your Host ID is in blue(this is the unique identifier for each device).

    Alternitavely, you could have a Subnet Mask of 255.255.0.0 which would denote two octets of 'Net ID' and two octets of 'Host ID', this is a much larger network as there are far more Host IDs available(255 Host IDs in the first example and roughly 65,000 Host IDs in the second example.)

    So you can loosely think of the Subnet Mask as a definition for the size of your network.

    Quote Originally Posted by billconan View Post
    for example, if i visit this http://whatismyipaddress.com/, it will tell me that my ip address is

    234.247.121.220
    This is the public interface of the top level in your network (most likely a router).

    Quote Originally Posted by billconan View Post
    and from my windows 7 settings, i know that my subnet mask is 255.255.255.0. so that means, i am the number 220 machine inside the subnet?
    Open cmd.exe and run the command: ipconfig /all
    This will tell you what your local IP address is and then you can figure out what your Host ID is based on your subnet mask.

    Quote Originally Posted by billconan View Post
    BTW, I'm using the wireless of my school.
    Every school I have ever been to uses Network Address Translation because it is far cheaper and easier to manage. So the IP address that you see on that website is the very top level router of your school network.



    Quote Originally Posted by billconan View Post
    or, the subnet mask is only for the subnet , it has nothing to do with my public ip?
    The subnet mask has nothing to do with your public IP address if you are using Network Address Translation.


    Quote Originally Posted by billconan View Post
    from my windows setting, my ipv4 address is 192.168.1.35 my subnet mask is 255.255.255.0, so really i am the number 35 machine of the subnet??
    Correct, 35 is your Host ID. Keep in mind this does not mean there are 35 devices on the network. There could be 5 or 200 devices on the network. This is just an identifier...you could even be the only device on the network.


    Quote Originally Posted by billconan View Post
    the second question is, if the subnet mask is only for the subnet, then why people say that ip address can be divided into class A, B, C and D??
    IP address classification is used to classify the Public IP Addresses so they can be organized and allocated correctly. This doesn't have much meaning once you are on a local network. Organizations like the IANA are responsible for managing IP addresses on a global scale and this is something they would have to worry about, not you.



    Quote Originally Posted by billconan View Post
    does a public ip also fall into one of the four classes?
    Every IP address falls into a classification. And like I said before, it really only matters when it comes to Public IPs. Once you have your own private network you can use whatever IPs you want(with some exceptions, such as 127.0.0.1, which is a loopback address hardcoded into every routing table on every router)



    Quote Originally Posted by billconan View Post
    if public ips also have different classes, then the overall ip addresses cannot be 2^32, because if you look at the class A ips, there are only 256 ips in total.
    I would re-check this information, Class A has more than 256 IPs...


    Quote Originally Posted by billconan View Post
    my third question is, if i want to build a home wireless network and i have two machines and an ap. why should i use the subnet mask 255.255.255.0?

    why can't i use 255.0.0.0? and who invented 192.168.x.x ??? why not something else?
    you can use whatever subnet mask you want on a private network. But there is no reason to use 255.0.0.0 because then you could have 16,581,375 devices !!


    Quote Originally Posted by billconan View Post
    can my ipv4 address be set to 175.0.0.2 and use 255.0.0.0 as the mask?
    Absolutely, on a private network. However, convention tells us to use the 255.255.255.0 and 192.168.1.xxx that you see everywhere, and it is best to stick with this. But I don't know of any reason why you CAN'T use those...

    Quote Originally Posted by billconan View Post
    if i were the inventor of the whole IP thing, i would give each public machine or a router an unique ip, but within each subnet, i would use integers, machine 1, machine 2, machine 3 ....

    why bother with subnet maskes?
    Ah, yes. Hindsight is always 20/20. Subnetting was ALWAYS required to successfully manage IP Addresses. HOWEVER, it is Network Address Translation that was designed to free up IP Addresses because we began to run out. So now, you can have one Public IP Address for one gigantic private network with several thousand of it's own devices. Effectively giving us a very large increase in 'Internet realty'.

    Before we started running out of IP Addresses, everything was a public IP Address. You could send someone a 'Ping of Death' accross the world if you wanted to. Now, most users are behind a router and on a local network so you can't get direct access to their computer.
    Last edited by Austin.Soucy; January 26th, 2011 at 06:08 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured