Net masks - the binary explanation
To really understand the operation of a net mask it is necessary to delve deeper
into the life blood of computers –
binary
; this is native digital, where everything
is either a 1 (one) or 0 (zero), on or off, yes or no.
The net mask operation described on the
previous page
is known as a ‘bit-wise
AND function’. The example of 255.255.255.0 is handy because the last octet
is completely zero and is “clean” for illustrative purposes. However, actual net
mask calculations are carried out, not on whole decimal numbers, but bit by bit
on binary numbers, hence the term ‘bit-wise’. In a real local network, a net mask
might be
255.255.255.240
. Such an example would no longer be quite so clear,
until you look at the net mask in its binary form:
11111111.11111111.11111111.
11110000
In this case, the four zeroes at the end of the net mask indicate that the local
part of the address is formed by only the last four bits. If you use the diagram
from the previous example and insert the new net mask, it will have the
following effect on the final result:
192
192
168
168
142
142
154
154
144
1
1
1
0
0
0
0
1
1
1
0
0
0
1
0
0
0
1110 0 0 0
144
Thus, when 154 is
bit-wise ANDed
with 240, the result is 144. Likewise, any
local address from 192.168.142.
144
through to 192.168.142.
159
would
produce exactly the same result when combined with this net mask, hence they
would all be local addresses. However, any difference in the upper three octets
or the upper four bits of the last octet would slip through the mask and the
address would be flagged as not being local.
Inside a bit-wise AND function
When you “open up” the last octet
of the net mask and look at the
binary inside, you can see the last
four zero bits preventing any 1’s in
the address from falling through.
Decimal octet prior to AND
operation with net mask
Binary equivalent of
Binary octet after AND
operation with net mask
Decimal equivalent of 000000