Yet another post about IPv4 subnetting (non contiguous bits version)

Prime knotDuring my current (fulfilling and rewarding actually) teaching activity, I’m seeing amazed faces when I talk about non-contiguous subnet masks.

I know, that’s a topic with some historic flavour, neverthless still good for reasoning and practicing.

This post is supposed to guide students through examples and explanations.

Jon Postel
Jon Postel

RFC 950, Internet standard subnetting procedure by Jon Postel and Jeffrey Mogul, is part of IETF Standard 5 and discusses the utility of “subnets” of Internet networks.

 

 

 

Postel and Mogul write:

“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.”

Jeffrey Mogul
Jeffrey Mogul

In the Appendix II of RFC 950, there is “A Class C Network Case (illustrating non-contiguous subnet bits)”: 


192.1.127.50
255.255.255.88

Here I’m going to make some other examples in order to show you the rationale behind non-contiguous subnet masks.

 

First example

Take this IPv4 address (IP)
0.1.2.3

and consider this non contiguous subnet mask (SM)
255.255.255.1

Now, you should calculate

  • Network-ID address (First IPv4 address)
  • Broadcast address (Last IPv4 address)
  • Number of available addresses for hosts

Convert both IP address and Subnet Mask to binary:


IP: 00000000.00000001.00000010.00000011
SM: 11111111.11111111.11111111.00000001

[Note: this subnet mask has non contiguous 1s]

Let’s first find out Network ID address (ID) by applying a bitwise AND

Logical Conjunction
Think of T like a 1 and F like a 0

bitwise AND


IP: 00000000.00000001.00000010.00000011
SM: 11111111.11111111.11111111.00000001
========================================
ID: 00000000.00000001.00000010.00000001

convert NET-ID back to decimal: 0.1.2.1

Let’s go ahead and calculate its broadcast address by operating a bitwise XOR between Network ID address and the inverse of our given subnet mask (ISM: replace 0s with 1s and vice versa)

Exclusive Disjunction
Think of T like a 1 and F like a 0

bitwise XOR


ID:  00000000.00000001.00000010.00000001
ISM: 00000000.00000000.00000000.11111110
========================================
BA:  00000000.00000001.00000010.11111111

The broadcast address calculated and converted to decimal is: 0.1.2.255

So far, so good with this traditional method and valid method for every subnetting exercise.

Now, observe with me what those non contiguous 1s are causing in the above bitwise ANDing and XORing operations.

Look at that less significant bit (rightmost 1) in the subnet mask: it determines the network ID in accordance with the corresponding bit in the address (rightmost 1 in the given example).

Since the less significant bit decides if the number is even or odd, we now fully understand when the network ID can be even or odd (rightmost 1 or 0) and when the broadcast address can be even or odd (255 or 254).

I’ll give an example with a different IP address 0.1.2.4 but same subnet mask 255.255.255.1.

Let’s get with the procedure:

bitwise AND


IP: 00000000.00000001.00000010.00000100
SM: 11111111.11111111.11111111.00000001
========================================
ID: 00000000.00000001.00000010.00000000

Network ID in decimal: 0.1.2.0

bitwise XOR


ID:  00000000.00000001.00000010.00000000
ISM: 00000000.00000000.00000000.11111110
========================================
BA:  00000000.00000001.00000010.11111110

Broadcast address in decimal: 0.1.2.254

So it’s easy to understand that with the subnet mask 255.255.255.1 we have two groups in the last octect, two different broadcast domains:

  1. the first one starting at 0.1.2.0, ending at 0.1.2.254 is participated by 128 even addresses allowing 126 (2^8/2-2) hosts to be numerated;
  2. the second one starting at 0.1.2.1, ending at 0.1.2.255 is participated by 128 odd addresses allowing 126 (2^8/2-2) hosts to be numerated.

255.255.255.1 non-contiguous bits

Watch this video proof of concept

Second example

IP: 0.1.2.3
SM: 255.255.255.64

bitwise AND


IP:  00000000.00000001.00000010.00000011
SM:  11111111.11111111.11111111.01000000
========================================
ID:  00000000.00000001.00000010.00000000

Network id in decimal: 0.1.2.0

bitwise XOR


ID:  00000000.00000001.00000010.00000000
ISM: 00000000.00000000.00000000.10111111
========================================
BA:  00000000.00000001.00000010.10111111

Broadcast address in decimal: 0.1.2.191

Let’s try with a different IP but same subnet mask:

IP: 0.1.2.65
SM: 255.255.255.64

bitwise AND


IP: 00000000.00000001.00000010.01000001
SM: 11111111.11111111.11111111.01000000
========================================
ID: 00000000.00000001.00000010.01000000

Network ID in decimal: 0.1.2.64

bitwise XOR


ID:  00000000.00000001.00000010.01000000
ISM: 00000000.00000000.00000000.10111111
========================================
BA:  00000000.00000001.00000010.11111111

Broadcast address in decimal: 0.1.2.255

What we have here is two split broadcast domains in the last octet:

  1. the first is from 0.1.2.0 to 0.1.2.63 and from 0.1.2.128 to 0.1.2.191;
  2. the second is from 0.1.2.64 to 0.1.2.127 and from 0.1.2.192 to 0.1.2.255.

255.255.255.64 non-contiguous bits

RFC 950 example

Finally, let’s try to figure out the example made in RFC 950:

192.1.127.50
255.255.255.88

bitwise AND


IP: 11000000.00000001.01111111.00110010
SM: 11111111.11111111.11111111.01011000
========================================
ID: 11000000.00000001.01111111.00010000

Network ID in decimal: 192.1.127.16

bitwise XOR


ID:  11000000.00000001.01111111.00010000
ISM: 00000000.00000000.00000000.10100111
========================================
BA:  11000000.00000001.01111111.10110111

Broadcast address in decimal: 192.1.127.183

Let’s go for another IP trying to discover this broadcast domain’s perimeter.

192.1.127.15
255.255.255.88


IP: 11000000.00000001.01111111.00000111
SM: 11111111.11111111.11111111.01011000
========================================
ID: 11000000.00000001.01111111.00000000

Network ID in decimal: 192.1.127.0

bitwise XOR


ID:  11000000.00000001.01111111.00000000
ISM: 00000000.00000000.00000000.10100111
========================================
BA:  11000000.00000001.01111111.10100111

Broadcast address in decimal: 192.1.127.167

192.1.127.58
255.255.255.88

bitwise AND


IP: 11000000.00000001.01111111.00111010
SM: 11111111.11111111.11111111.01011000
========================================
ID: 11000000.00000001.01111111.00011000

Network ID in decimal: 192.1.127.24

bitwise XOR


ID:  11000000.00000001.01111111.00011000
ISM: 00000000.00000000.00000000.10100111
========================================
BA:  11000000.00000001.01111111.10111111

Broadcast address in decimal: 192.1.127.191

It seems that those two segments are overlapping: from 192.1.127.16 to 192.1.127.55; from 192.1.127.24 to 192.1.127.191.
It should be better verified.

192.1.127.120
255.255.255.88

bitwise AND


IP: 11000000.00000001.01111111.01111000
SM: 11111111.11111111.11111111.01011000
========================================
ID: 11000000.00000001.01111111.01011000

Network ID in decimal: 192.1.127.88

bitwise XOR


ID:  11000000.00000001.01111111.01011000
ISM: 00000000.00000000.00000000.10100111
========================================
BA:  11000000.00000001.01111111.11111111

Broadcast address in decimal: 192.1.127.255

It turns out that there are more than three fragmented broadcast domains, so let me write down all the possibilities inside the last 8 bits of the address.

bitwise AND
IP: 00000000 0,1,2,3,4,5,6,7
SM: 01011000
ID: 00000000 0

bitwise XOR
ID: 00000000
ISM:10100111
BA: 10100111 167

====================
bitwise AND
IP: 00001000 8,9,10,11,12,13,14,15
SM: 01011000
ID: 00001000 8

bitwise XOR
ID: 00001000
ISM:10100111
BA: 10101111 175

====================
bitwise AND
IP: 00010000 16,17,18,19,20,21,22,23
SM: 01011000
ID: 00010000 16

bitwise XOR
ID: 00010000
ISM:10100111
BA: 10110111 183

====================
bitwise AND
IP: 00011000 24,25,26,27,28,29,30,31
SM: 01011000
ID: 00011000 24

bitwise XOR
ID: 00011000
ISM:10100111
BA: 10111111 191

====================
bitwise AND
IP: 00100000 32,33,34,35,36,37,38,39
SM: 01011000
ID: 00000000 0

bitwise XOR
ID: 00010000
ISM:10100111
BA: 10110111 167

====================
bitwise AND
IP: 00101000 40,41,42,43,44,45,46,47
SM: 01011000
ID: 00001000 8

bitwise XOR
ID: 00001000
ISM:10100111
BA: 10101111 175

====================
bitwise AND
IP: 00110000 48,49,50,51,52,53,54,55
SM: 01011000
ID: 00010000 16

bitwise XOR
ID: 00010000
ISM:10100111
BA: 10110111 183

====================
bitwise AND
IP: 00111000 56,57,58,59,60,61,62,63
SM: 01011000
ID: 00011000 24

bitwise XOR
ID: 00011000
ISM:10100111
BA: 10111111 191

====================
bitwise AND
IP: 01000000 64,65,66,67,68,69,70,71
SM: 01011000
ID: 01000000 64

bitwise XOR
ID: 01000000
ISM:10100111
BA: 11100111 231

====================
bitwise AND
IP: 01001000 72,73,74,75,76,77,78,79
SM: 01011000
ID: 01001000 72

bitwise XOR
ID: 01001000
ISM:10100111
BA: 11101111 239

====================
bitwise AND
IP: 01010000 80,81,82,83,84,85,86,87
SM: 01011000
ID: 01010000 80

bitwise XOR
ID: 01010000
ISM:10100111
BA: 11110111 247

====================
bitwise AND
IP: 01011000 88,89,90,91,92,93,94,95
SM: 01011000
ID: 01011000 88

bitwise XOR
ID: 01011000
ISM:10100111
BA: 11111111 255

====================
bitwise AND
IP: 01100000 96,97,98,99,100,101,102,103
SM: 01011000
ID: 01000000 64

bitwise XOR
ID: 01000000
ISM:10100111
BA: 11100111 231

====================
bitwise AND
IP: 01101000 104,105,106,107,108,109,110,111
SM: 01011000
ID: 01001000 72

bitwise XOR
ID: 01001000
ISM:10100111
BA: 11101111 239

====================
bitwise AND
IP: 01110000 112,113,114,115,116,117,118,119
SM: 01011000
ID: 01010000 80

bitwise XOR
ID: 01010000
ISM:10100111
BA: 11110111 247

====================
bitwise AND
IP: 01111000 120,121,122,123,124,125,126,127
SM: 01011000
ID: 01011000 88

bitwise XOR
ID: 01011000
ISM:10100111
BA: 11111111 255

====================
bitwise AND
IP: 10000000 128,129,130,131,132,133,134,135
SM: 01011000
ID: 00000000 0

bitwise XOR
ID: 00000000
ISM:10100111
BA: 10100111 167

====================
bitwise AND
IP: 10001000 136,137,138,139,140,141,142,143
SM: 01011000
ID: 00001000 16

bitwise XOR
ID: 00010000
ISM:10100111
BA: 10110111 183

====================
bitwise AND
IP: 10010000 144,145,146,147,148,149,150,151
SM: 01011000
ID: 00010000 16

bitwise XOR
ID: 00010000
ISM:10100111
BA: 10110111 183

====================
bitwise AND
IP: 10011000 152,153,154,155,156,157,158,159
SM: 01011000
ID: 00011000 24

bitwise XOR
ID: 00011000
ISM:10100111
BA: 10111111 191

====================
bitwise AND
IP: 10100000 160,161,162,163,164,165,166,167
SM: 01011000
ID: 00000000 0

bitwise XOR
ID: 00000000
ISM:10100111
BA: 10100111 167

====================
bitwise AND
IP: 10101000 168,169,170,171,172,173,174,175
SM: 01011000
ID: 00001000 8

bitwise XOR
ID: 00001000
ISM:10100111
BA: 10101111 175

====================
bitwise AND
IP: 10110000 176,177,178,179,180,181,182,183
SM: 01011000
ID: 00010000 16

bitwise XOR
ID: 00010000
ISM:10100111
BA: 10110111 183

====================
bitwise AND
IP: 10111000 184,185,186,187,188,189,190,191
SM: 01011000
ID: 00011000 24

bitwise XOR
ID: 00011000
ISM:10100111
BA: 10111111 191

====================
bitwise AND
IP: 11000000 192,193,194,195,196,197,198,199
SM: 01011000
ID: 01000000 64

bitwise XOR
ID: 01000000
ISM:10100111
BA: 11100111 231

====================
bitwise AND
IP: 11001000 200,201,202,203,204,205,206,207
SM: 01011000
ID: 01001000 72

bitwise XOR
ID: 01001000
ISM:10100111
BA: 11101111 239

====================
bitwise AND
IP: 11010000 208,209,210,211,212,213,214,215
SM: 01011000
ID: 01010000 80

bitwise XOR
ID: 01010000
ISM:10100111
BA: 11110111 247

====================
bitwise AND
IP: 11011000 216,217,218,219,220,221,223
SM: 01011000
ID: 01011000 88

bitwise XOR
ID: 01011000
ISM:10100111
BA: 11111111 255

====================
bitwise AND
IP: 11100000 224,225,226,227,228,229,230,231
SM: 01011000
ID: 01000000 64

bitwise XOR
ID: 01000000
ISM:10100111
BA: 11100111 231

====================
bitwise AND
IP: 11101000 232,233,234,235,236,237,238,239
SM: 01011000
ID: 01001000 72

bitwise XOR
ID: 01001000
ISM:10100111
BA: 11101111 239

====================
bitwise AND
IP: 11110000 240,241,242,243,244,245,246,247
SM: 01011000
ID: 01010000 80

bitwise XOR
ID: 01010000
ISM:10100111
BA: 11110111 247

====================
bitwise AND
IP: 11111000 248,249,250,251,252,253,254,255
SM: 01011000
ID: 01011000 88

bitwise XOR
ID: 01011000
ISM:10100111
BA: 11111111 255

====================

Curious about results?

Look at this table:
RFC 950 - non contiguous bits

We found 8 split broadcast domains made of 32 addresses each. Every broadcast domain is divided into four 8-addresses-block.

Turning back to the example shown in RFC 950, the host 192.1.127.19 and the gateway 192.1.127.50 lay on the same broadcast domain, even if they are on non-contiguous network segments.

Leave a Reply