Network Engineering Stack Exchange is a question and answer site for network engineers. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Given a prefix Y, it's easy to calculate the corresponding netmask: Put Y times a set bit, and then fill up "to the right" with zeros until one has 32 bits (IPv4) in total.

Example:

Prefix 24, thus netmask 11111111 11111111 11111111 00000000 or 255.255.255.0.

Can there be a netmask with a different bit pattern, such as

  • 00000000 11111111 00000000 11111111 (0.255.0.255)
  • 00000000 11111111 11111111 11111111 (0.255.255.255)
  • 11111111 11111111 11111111 00000001 (255.255.255.1)

Specifying a "prefix" obviously wouldn't work for these cases.

(I'm pretty sure the answer is "NO", but I'm writing some network code, and this needs to work in all possible cases, so I want to be 101% sure.)

share|improve this question
up vote 4 down vote accepted

RFC950 states that

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.

Most devices follow this recommendation as far as to enforce it. I have only managed to use non-contiguous subnet masks on Linux-only networks back in 2012; the Windows, OSX, Cisco and HP devices I tested didn't handle/allow it.

share|improve this answer

If you are using prefixes and networks, then the answer is no, the bits need to be contiguous. There are cases where a wildcard mask (inverse of mask) can be used, e.g. Cisco ACLs, and those can be any bit pattern. For instance, you could block traffic from all the odd numbered hosts on a network. This seems to still be taught, but I have not seen it used very often (although I have seen it) in the real world.

share|improve this answer

No. A netmask is a continuous series of ones.

(The others are "wildcard" patterns.)

share|improve this answer
1  
This is not true. 30 years ago there were lots. There still may be some in operation. – MAP yesterday
2  
I highly doubt that. No modern routing hardware will allow it. And routers from the 80s will have numerous problems with the way IP works today. (Been there. Told ya' not use the all zero subnet -- even in the late '90s that was a problem) The only two devices I still have from that era will not accept a non-contiguous netmask. (WTI pdus, still around because they have 10bT ports. Nothing talks to them, most of all the internet.) – Ricky Beam yesterday

When TCP/IP first came out and got widespread, there were actually a lot of subnets with non-contiguous masks. But as addresses became scarce, the overhead to the rest of the net to allow global routing of these prefixes rather than forcing everything to be only prefix based; was too much and the global network changed to only supporting prefixes. There may actually still be legacy networks that use non-contiguous masks internally (many IGPs support this, still). But, when such a network connects to The Internet, it has a single prefix that covers all of them, that it advertises into BGP. And, of course, EGP (the predecessor to BGP) only supported Classful addressing.

I know several players with original issue Class A networks that used non-contiguous netmasks internally for one reason or another. I just don't know if any of them are still doing it. A lot of them don't even exit any more. The ARPAnet had an internal netmask of 255.0.0.255 (IIRC).

share|improve this answer
2  
NONSENSE. This has nothing to do with CIDR, or classes, or aggregation. A netmask has ALWAYS been contiguous. – Ricky Beam yesterday
2  
@MAP Would you happen to have any supporting reference for this? Perhaps a legacy RFC? Even a relevant news article might provide some context for debate. – Ryan Foley yesterday
5  
See RFC 950, for example. Page 15 gives an example with a netmask of 255.255.255.88. – Ross Presser yesterday
3  
I think page 12 of RFC 1519 actually hurts your case since the only relevant sentence is, "The only outstanding constraint is that the mask must be left contiguous." (Emphasis mine) Since the mask is implied/assumed by the class in classful routing, and only three contiguous masks were used, and the RFC on CIDR specifies contiguous masks, it seems like your answer is wrong. The FreeBSD list post is a mystery to me. – Todd Wilcox yesterday
3  
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. While that does not carry the SHOULD/MUST wording used today, that is exactly how everyone has built modern subneting capabilities. Over 3 decades of networking, I have never encountered technology that allows discontiguous subnets. – Ricky Beam yesterday

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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