Subnets and Subnet Masking
IP network addresses are given in the form <network><host>
(or, if subnetted, <network><subnet><host>)
when viewed in binary notation. Masks determine how much of the
address is network, and how much host.
For a standard Class B address, the mask is 255.255.0.0, hence
the first 2 octets are network and the last two are available
for hosts (PCs, servers, etc.).
For Class C, the mask is 255.255.255.0, which means that only
the last octet (256 addresses) is available for hosts.
In binary; the masks are:
Class B: 11111111.11111111.00000000.00000000
Class C: 11111111.11111111.11111111.00000000
Host numbers which are all zeroes or all ones are not allowed,
hence a Class C address cannot be xxx.xxx.xxx.0 or xxx.xxx.xxx.255,
giving 254 useable addresses.
Applying a mask.
A subnet mask increases the amount of address that is deemed to
be "network" thereby reducing the amount of host for
each address.
e.g. Class C address 194.64.48.86, mask 255.255.255.240
In binary:
Address 11000010.01000000.00110000.01010110
Mask 11111111.11111111.11111111.11110000
So the network is the 28 most significant bits.
To determine the subnet, the address is ANDed with the mask.
Address 11000010.01000000.00110000.01010110
Mask 11111111.11111111.11111111.11110000
=========================================
ANDed 11000010.01000000.00110000.01010000
Thus, to determine whether two addresses are in the same subnet,
the address is ANDed with the mask, and the two results compared.
E.g. Is 194.64.48.86 in the same subnet as 194.64.48.162, when
a mask of 255.255.255.240 is applied?
Address 11000010.01000000.00110000.01010110 194.64.48.86
Mask 11111111.11111111.11111111.11110000 255.255.255.240
=======================================================
ANDed 11000010.01000000.00110000.01010000 194.64.48.80
Address 11000010.01000000.00110000.10100010 194.64.48.162
Mask 11111111.11111111.11111111.11110000 255.255.255.240
========================================================
ANDed 11000010.01000000.00110000.10100000 194.64.48.160
Subnets are 194.64.48.80 and 194.64.48.160, so they are not in
the same subnet.
Only the last octet need really be considered when testing this
- 195.200.21.50 is clearly not the same network!
Also, if the subnet is applied in this way, simply determining
the least significant bit of the mask (in our case, 100002
or 16) gives the number of addresses in each subnet, so the addresses
will be 0-15, 16-31, 32-47, 48-63, etc. As "all zero"
and "all one" addresses are not allowed, 194.64.48.0,
194.64.48.15, 194.64.48.16, 194.64.48.31, 194.64.48.32, etc. are
not legitimate when masked to 255.255.255.240 (in binary, these
make the last 4 bits all zeroes or all ones; these are the host
addresses reserved for network or broadcast).
Silly Subnets
It is possible (and legal!) to apply odd subnet masks to addresses,
such as to subnet a Class B by 255.255.55.57 (In binary, 11111111.11111111.00110111.00111001)
but this causes severe headaches as you need a scientific calculator
to work out each and every address for the subnet - try ANDing
this sort of mask!
|