Every netmask I've ever encountered is a prefix, neatly expressible by the CIDR notation: /8 for, /16 for and /24 for

Of course, we can change the length of the netmask and get a lot of different values.

The question is, can a netmask exist on which the "network bits" are not a prefix of the address? Something like

  • Techically, yes, the "netmask" concept allows it. However, they're nonsensical, as they don't fit into the hierarchical routing, so in practice they'll be rejected.
    – user1686
    Aug 19 '15 at 5:29

Depends a bit of what you want to do with it.

In the olden days the netmask really was a mask that was applied to the IP address. However, with the introduction of CIDR everybody expects a string of ones (1) followed by zeroes (0) now. You can bet that high-speed core routers are now optimized for this pattern and get confused with different bitmasks.

For local, static networks you can still use a mask like and even tie networks together with such masks. But if you encounter a router that only accepts CIDR notation you won't be able to route properly.

  • While it is true that the Subnet Mask is no longer used to differentiate the network address from the subnet address from the host address, even in modern CIDR scenarios the Network address must be indicated by contigious 1's in the mask. At best, were the 1's to be discontigious, the network address would be assumed to end at the position of the first 0 in the mask by most hardware, and even if the hardware can process it, the mask would be meaningless, since you can't differentiate the network address from the host. CIDR got rid of classic subnets, but doesn't change anything else. Aug 18 '15 at 17:08
  • We know the CIDR "mask" is a string of 1's followed by 0's. However, the OP asked if a different, non contiguous bitmask is possible. The answer to that is yes, if the software/hardware supports it. E.g. on a Linux machine where all IP routing is done in software that mask will work. But the moment you hit a piece of hard- or software that only supports CIDR, you're out of luck.
    – JvO
    Aug 18 '15 at 19:21
  • 1
    but it would have no meaning for the software to support, so supporting the doing of nothing seems absured. the mask the op provided has expresses no meaningful information to the IP stack, so its going to handle it exceptionally (probably by ignoring everything after the first 0), and expose no actual function. What is it you expect this mask to do exactly? Aug 18 '15 at 19:27

No. The definition of IP address networks specifies that the first part is the constant part that appears in all hosts, and the second part is the variable part that applies to the individual hosts. A netmask must be a string of 1s followed by a string of 0s.

Whoever decided to down-vote me should read https://en.wikipedia.org/wiki/Subnetwork


No, because that is not a Mask. The Mask is defined so that if you AND the address and the mask, the network bits will always remain as is, and the host bits are all 0's.

For example if we AND together the IP and the MASK, we get this:

00110010 00101010 11100011 10101010
11111111 11111111 00000000 00000000
00110010 00101010 00000000 00000000

A non-contigious mask as you suggest could not do that. Here is an interesting document on the binary nature of IP addresses/masks.

The value you suggest could be used as a Pattern for matching specific IP addresses, when the mask is applied, but as it would essentially ignore the second octet of ANY IP address that it attempted to process, routers and other devices would not be able to determine the network address correctly, and thus could not deliver the traffic as expected.

Note that the binary AND operation and the nature of the mask itself was designed to be calculated in hardware with a single operation over a pair of registers, and an AND is about as basic as logical operations come.


Not sure why the downvote, but I would point out that per RFC 1519 (CIDR), Masks must be contigious to the left:

An implementation following these rules should also be generalized, so that an arbitrary network number and mask are accepted for all routing destinations. The only outstanding constraint is that the mask must be left contiguous.

The only case in which an address might use non-contigious masking is (per RFC 950):

  1. Classful Subnetting is in use
  2. The "odd" bits must occur in the final octet of the mask that is meaningful (eg,

Since the bits that identify the subnet are specified by a bitmask, they need not be adjacent in the address. However, we recommend that the subnet bits be contiguous and located as the most significant bits of the local address.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.