IP Routing Primer: Part One
November 6, 2000
by Peter
Morrissey
In
many ways, the task of a router is very simple. It
must look at the destination address of an IP packet and then forward
the packet to another router or to a directly connected host. However,
if youŭve ever attempted to get two devices to communicate on an IP
network, you know that it doesnŭt always work.
In this Network Design Manual article weŭll show
you the steps involved in getting a packet from Point A to Point
B on an IP network. Weŭll talk about the settings that are necessary
on a host to communicate on a routed network and what they really
mean. Once you understand this, youŭll be able to ask the right
questions when things donŭt go as expected and even do a little
bit of your own troubleshooting.
Anatomy of an IP Address
When one host has data to send to another host, it
sends it to its local IP process, which builds an IP packet for transmission
on the network. The packet has a header, which includes the destination
IP address as well as the source address of the local host. The destination
and source IP addresses stay with the data until it arrives at the
host so that all the routers it traverses know in what direction to
send it. The source address provides the destination host with an
address to which it can send its response.
To understand how this happens requires a deeper
knowledge of the IP address. It's obvious that an IP address consists
of four separate numbers, separated by dots. Each number represents
one byte worth of data, limiting it to a range of 256 possible values,
commonly represented as decimal values from 0 to 255 or binary values
from 00000000-11111111.
One thing that is not so obvious is that each IP
address is always divided in to two sections. The first section
always delineates the network address, or subnet. This is the part
routers are primarily concerned with. The second section, combined
with the first section forms a unique node address. The subnet mask
is configured to tell the host or client which part is the network
address and which part is the node address.
Subnet Masks
The subnet mask is a required setting on any host that
communicates on an IP network. It is commonly represented in the same
format as an IP address, except that the values usually are either
255 or 0. (Exceptions to this are becoming more common--we'll talk
about those later). If you've ever seen a subnet mask, you will notice
that a series of one or more 255 values are always designated in succession,
followed by a series of 0 values. If you line a subnet mask up over
an IP address by the dots, each number below a 255 will be part of
the network address. The remaining numbers under the 0s will be the
node address.
| 255.255.255.0 |
= mask |
| 128.230.100.4 |
= IP address |
With this type
of subnet mask, the boundary between the network and node address
is always on a dot between the last 255 and the first 0, sometimes
referred to as the byte boundary.
What really matters to a computer of course is
the binary representation. The above mask and IP address are represented
in the following manner as binary:
| 11111111.11111111.11111111.00000000 |
Mask |
| 10000000.11100110.01100100.00000100 |
IP
Address |
With the binary representation, an uninterrupted
sequence of 1s in the mask, line up exactly over the subnet portion
of the address. With this type of mask, seeing the binary version
doesn't add any value, but later it will be necessary to see the
binary data to fully understand masks that don't end neatly on one-byte
boundaries.
Part of the decision as to how to set up the subnet
mask is left to the network designer, but the subnet mask must be
configured consistently throughout the network. Another factor that
limits the definition of a subnet mask is its class. For example,
with a "Class B" address, the first two bytes always have to be
included in the network portion of the address, and thus the subnet
mask will always start out with 255.255 or 11111111.11111111. With
a "Class C" address, the first three bytes have to always be included
in the network portion of the address. In this case the subnet mask
would have to start with 255.255.255.
In each instance, there is a lot of flexibility
in the way that the rest of the address is masked. The example above
is a Class B address. The network address is 128.230.100. The node
address is 4. The example above used a subnet mask of 255.255.255.0.
This makes it possible to have 254 unique, routed networks or subnets
because the mask can include the third byte in the network address.
(You can't use 255 because that's reserved for broadcast address,
and 0s, used in an older style of broadcast address, can't be used
either; 0s at the end of an address are also used to symbolize network
addresses.) Even though the first two bytes cannot be changed, the
third byte can have any value from 1 to 254. This means that with
a three-byte or 24-bit subnet mask, the following distinct networks
or subnets are possible with the address:
| 128.230.1.0 |
-- |
128.230.254.0 |
There is one byte left over for node addresses, so
each network or subnet will have 254 node addresses. If the minimum
subnet mask of 255.255.0.0 were used, there could only be one routed
network. But two bytes would be left over for node addresses. So
the range of possible node addresses would be 128.230.1.1 to128.230.254.254
or approximately 65,000 nodes. The disadvantage of this is that
you cannot divide your network into routed subnets.
With this particular address, if you divide only
the subnet mask on the byte boundaries, you have 254 subnets limited
to 254 nodes each, or you have one big network with 65,000 nodes.
These two extremes have some obvious trade-offs. There may be cases
where you would want more than 254 nodes on a routed subnet, but
the other extreme flattens the network completely, giving you no
ability to divide your network into routed subnets.
Fortunately, the subnet mask doesn't have to divide
the network address and the node address on a dot boundary. In some
cases it can be divided somewhere in between. When the network address
and node address are not divided on a dot boundary, the subnet mask
is called a variable-length subnet mask. A variable-length subnet
mask is commonly represented in decimal form, such as 255.255.254.0.
But its binary representation has to be considered to understand
where the network address ends and the node addresses can begin.
The following example uses a subnet mask of 255.255.254.0:
| 255.255.254.0 |
= mask |
| 128.230.00.2 |
= IP address |
To understand this, we'll have to look at it in binary
form. Here the mask does not line up on the byte boundaries:
| 255.255.254.0 |
=
11111111.11111111.11111110.00000000 |
Mask |
| 128.230.004.2 |
=
10000000.11100110.00000100.00000010 |
IP Address |
One thing you should notice is that there are contiguous
1s from left to right in the subnet mask. This is one of the rules
of a subnet mask: All the binary 1s have to be contiguous, and all
the following 0s overlaying the node address have to be contiguous.
A mask that doesn't follow this pattern is not valid. In any case,
the valid node addresses are all possible numbers that can be represented
under the 0s, so the lowest number is going to be: 128.230.4.1 or
10000000.11100110.00000100.00000001. And the highest number is going
to be 128.230.5.254 or 10000000.11100110.00000101.11111110. You will
also notice that this mask has one less one bit than the previous
mask. This is sometimes referred to as a 23-bit mask.
| 11111111.11111111.11111110.00000000 |
=
255.255.254.0 |
=
mask |
| 10000000.11100110.00000100.00000000 |
=
128.230.004.0 |
=
network address |
| 10000000.11100110.00000100.00000010 |
=
128.230.004.2 |
=
node address |
| 10000000.11100110.00000100.00000001 |
=
128.230.004.1 |
=
lowest possible node address |
| 10000000.11100110.00000101.11111110 |
=
128.230.005.254 |
=
highest possible node address |
Because subnet masks have to be contiguous 1s followed
by contiguous 0s, the last byte of a subnet mask can only have the
following binary or decimal values:
| 11111111 |
= 255 |
| 11111110
|
=
254 |
| 11111100 |
=
252 |
| 11111000 |
=
248 |
| 11110000 |
=
240 |
| 11100000 |
=
224 |
| 11000000 |
=
192 |
| 10000000 |
=
128 |
| 00000000 |
=
0 |
Broadcast Addresses
There are times when a device has to send an IP packet
to every node on a network. In such an instance, it will use the broadcast
address of that network. The subnet mask is also used to derive the
broadcast address. This is done by replacing all of the binary digits
in the node address, as governed by the trailing 0s in the mask, to
values of binary ones. This is combined with the network address,
which results in the broadcast address. Following is the broadcast
address that would go with our above example.
| 11111111.11111111.11111110.00000000 |
=
255.255.254.0 |
=
mask |
| 10000000.11100110.00000100.00000000 |
=
128.230.004.0 |
=
network address |
| 10000000.11100110.00000101.11111111 |
=
128.230.005.255 |
=
broadcast address |
Broadcast addresses also are easier to figure out when
the masks end on the one-byte boundaries. When this is the case, it
can easily be represented in decimal by substituting decimal 255s
in place of the bytes where the mask indicates the node address belongs.
Here's an example:
| 255.255.255.0 |
= mask |
| 128.230.4.0 |
= network address |
| 128.230.4.255 |
= broadcast
address |
|