Internet Protocol, or IP, is a commonly used layer 3 protocol. It is often used in conjuntion with the TCP suite of protocols at layer 4, including UDP and ICMP, among others.
IP is used primarily as an addressing scheme that extends beyond layer 2 addressing, which is only valid locally. An IP address is a 32-bit number, usually represented in dotted decimal notation (DDN). This means each 8 bits are represented in decimal with a dot between them. An example IP address is 128.169.50.100.
IP addresses are grouped into 5 categories, A through E. Each category reserves a certain number of bits for the network number, and a certain number of bits for the local address.
Class A has a 7-bit network number and a 24-bit local address. The highest order bit is always set to zero. This allows 128 (2^7) class A networks.
| class A addresses | |
| 0.0.0.0 | Reserved |
| 1.0.0.0 to 126.0.0.0 | Available |
| 127.0.0.0 | Reserved (localhost) |
Class B network addresses have a 14-bit network number, a 16-bit local address, and they begin with "10" binary. This allows 16,384 class B networks.
| class B addresses | |
| 128.0.0.0 to 191.254.0.0 | Available |
| 191.255.0.0 | Reserved |
Class C network addresses have a 21-bit network number, an 8-bit local address, and they begin with "110" binary. This allows 2,097,152 class B networks.
| class C addresses | |
| 192.0.0.0 | Reserved |
| 192.0.1.0 to 223.255.254.0 | Available |
| 223.255.255.0 | Reserved |
Class D network addresses are for multicasting.
| class D addresses | |
| 224.0.0.0 to 239.255.255.255 | multicast group |
Class E network addresses being with 4 binary ones, and this is not allowed. The one exception to this rule is the address where all the bits are ones (255.255.255.255); this is reserved for an IP broadcast.
| class E addresses | |
| 240.0.0.0 to 255.255.255.254 | reserved (illegal) |
| 255.255.255.255 | reserved (broadcast) |
Often an IP network needs to be divided into smaller networks, called subnets. As an example, for any given class B network, there are 65,534 (2^16 - 2) usable addresses. This is usually way too many computers to have on any one physical segment of the LAN. This problem is resolved by breaking the network into multiple smaller networks. The number of hosts and range of addresses for each subnet is determined by a subnet mask that is applied to the network. A subnet mask is a 32-bit number like an IP address. It is also usually represented in DDN.
Let us consider an easier example than the one above to begin
with. Let us say that we have a class C network, 192.168.0.0.
Class C networks have an 8-bit local number, meaning 256 addresses
are available per network.
The addresses for the network will range from
192.168.0.0 to 192.168.0.255. The bottom address (192.168.0.0)
is the network number (or net ID) and the top number
(192.168.0.255) is the broadcast address for the network. These
two addresses are automatically in use, so that leaves 253 addresses
available for computers (or hosts). 253 hosts is too many for us
(for whatever reason), so we need to decide how many hosts we can
accomodate at once. A power of 2 should always be chosen, so let
us choose 32 hosts per subnet. Since usually a total of 256 local
addresses are available, there will be 8 (256 / 32) subnets
created:
192.168.0.0 to 192.168.0.31
192.168.0.32 to 192.168.0.63
192.168.0.64 to 192.168.0.95
192.168.0.96 to 192.168.0.127
192.168.0.128 to 192.168.0.159
192.168.0.160 to 192.168.0.191
192.168.0.192 to 192.168.0.223
192.168.0.224 to 192.168.0.255
In each of the above subnets, the first number is the network ID,
and the second number is the broadcast address for the subnet. The
remaining 30 addresses can then be used by hosts on the subnet.
So how can this scheme be applied? A subnet mask must be determined
that explains the above scenario. To understand a subnet mask,
it must be thought of in terms of binary. The 32 bits of the mask
represent which bits may vary within a subnet, and which bits must
remain constant. The variable bits are represented as 0's, and
the constant bits as 1's. Since in our example we want 32
addresses per subnet, we must have 5 bits as 0's and the rest as
1's, because 2^5 = 32. So our mask will be:
11111111.11111111.11111111.11100000 (dots left in for readability)
That is 255.255.255.224 in DDN.
Let us now consider another problem: given an IP address of a host, and a subnet mask, how can one determine the net ID and broadcast address of the subnet? The net ID is found by doing a logical AND operation with the IP address and the mask. If you are unfamiliar with ANDing, please refer to the following truth table:
| A | B | A AND B |
| 0 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
In other words, both values must be 1 for the result to be 1. Let us say that we have an IP of 192.168.0.133 with a subnet mask of 255.255.255.224. Let us AND them together:
IP = 192.168.0.133 = 11000000.10101000.00000000.10000101
MASK = 255.255.255.224 = 11111111.11111111.11111111.11100000
AND = 192.168.0.128 = 11000000.10101000.00000000.10000000 = The net ID
Now the upper limit of addressing, the broadcast address, of the
subnet can be found. Perhaps the simplest way to do this is to
find the next net ID. To do this, look at the rightmost masked
bit in the subnet mask. In the example, this is the decimal
value of 32 in the fourth octet. Therefore, to find the next
net ID, add 32 to the fourth octet of the current net ID:
Next net ID = 192.168.0.160
The broadcast address is one less that the next net ID:
Broadcast address = 192.168.0.159
To recap what we determined in this example:
IP address = 192.168.0.133
Subnet Mask = 255.255.255.224
Net ID = 192.168.0.128
Broadcast address = 192.168.0.159
Range of allowable host addresses: 192.168.0.129 to 192.168.0.158