• Aceticon@lemmy.dbzer0.com
    link
    fedilink
    English
    arrow-up
    3
    ·
    8 hours ago

    If a bit in those 4 bytes is 1 that means that the same bit in the IP address is part of what defines the network whilst the bits that are 0 are bits that can change in the IP address and that machine will still be part of that sub-network.

    So a mask of 255.255.252.0 (notice the 3rd byte) on a network with a prefix 192.168.0.0 means that 192.168.0.20 is in that sub-network AND 192.168.2.20 is part of that sub-network too, because the two lowest bits of the 3rd byte in that mask are 0, meaning that IP address where those bits vary are still in the same sub-network (i.e. the ranges 192.168.0.XXX, 192.168.1.XXX, 192.168.2.XXX and 192.168.3.XXX are all in the same sub-network).

    If instead the sub-network prefix was the same 192.168.0.0 but with a mask of 255.255.255.0 (the most common case you find in home internal networks) then 192.168.2.20 would NOT be part of the same sub-network as 192.168.0.20

    You probably also see now why a network mask is needed alongside the network prefix - in both examples above 192.168.0.0 is the network prefix, but without the network mask you don’t know which 0 bits in that network code can be changed to make an IP address still in the same sub-network.

    Note that you can change the mask to make the sub-network smaller as well as to make them bigger: for example 192.168.0.0/255.255.255.223 is a perfectly valid subnetwork that fits 30 machines.

    See chronicledmonocle@lemmy.world 's post for a full explanation.

    • sem@lemmy.blahaj.zone
      link
      fedilink
      arrow-up
      2
      ·
      5 hours ago

      Thankyou! So when I see things like 192.168.1.0/24, is that CIDR notation? And does that do a similar thing of the subnet mask by telling you which addresses are part of the subnetwork?

      Can you have CIDR and subnet mask at the same time?

      • Aceticon@lemmy.dbzer0.com
        link
        fedilink
        English
        arrow-up
        2
        ·
        5 hours ago

        Well, a network mask is by definition always a sequence of 1s followed by 0s (in other words, you can’t arbitrarilly have some bits be 0 in between bits which are 1), so that /24 in CIDR notation is literally “/” + the number of bits in the network mask which have the value 1.

        In other words, because of that “sequence of 1s followed by 0s” rule both 255.255.255.0 and /24 are just two different descriptions of the same network mask, first as 4 decimal numbers separated by dots, whilst the second as the count of bits in the binary representation of the mask which have the value 1.

        For example, the 255.255.252.0 network mask from my first example in my last post could also be represented by /22 since the mask has 8+8+6 = 22 bits with value 1 and the rest are 0 - 192.168.0.0/22 means the same as 192.168.0.0/255.255.252.0

        There is no point in having both that part of the CIDR representation and the decimal mask representation at the same time because they’re both different representations of the same thing so having both is redundant.

        • sem@lemmy.blahaj.zone
          link
          fedilink
          arrow-up
          2
          ·
          4 hours ago

          Thanks, that rule about which masks are allowed was definitely not clear to me at first, thank you

          • Blaster M@lemmy.world
            link
            fedilink
            English
            arrow-up
            1
            ·
            1 hour ago

            Depends on the equipment. I prefer cidr because its simpler, and ipv6 uses CIDR. Do you want to spell out a /64 in a netmask format? It would look like this: 255.255.255.255.255.255.255.255.0.0.0.0.0.0.0.0