Class | Network Address | Prefix | Host Address |
---|---|---|---|
A | First 8 bits | 0 | Last 24 bits |
B | First 16 bits | 10 | Last 16 bits |
C | First 24 bits | 110 | Last 8 bits |
The network address is part that is assigned to the organization by the IANA. It is fixed for the organization. The host address is the part that can be assigned by the organization. This is the variable part, and can assigned any combination of 0s and 1s by the organization.
A subnet mask is a way of partitioning the organization's network into subnets. A subnet mask can be an important piece of information for a router or switch to perform its job efficiently.
Example:
Suppose you want to partition a Class C address into subnets, each having a subnet address of 27 bits. A subnet mask is used by a router to learn which of the bits in an address refer to the subnet and which bits refer to the host. Suppose the Class C address is 205.34.15.69, which in binary is 11001101.00100010.00001111.01000101 The subnet mask, constructed in binary, consists of a 1 marking each bit of the subnet address and a 0 marking each bit of the host address. In this case the subnet mask consists of 27 1-bits followed by 5 0-bits:
  | Binary | Dotted Decimal |
---|---|---|
Address | 11001101.00100010.00001111.01000101 | 205.34.15.69 |
Binary Subnet Mask | 11111111.11111111.11111111.11100000 | 255.255.255.224 |
Network Address | 11001101.00100010.00001111.01000000 | 205.34.15.64 |
How many possible hosts addresses are there on the subnet ? Answer: 25 = 32.
Example:
The Class B address 131.5.252.19 is part of a subnet where the first 23 bits form the subnet address and the last 9 bits form the host address. What is the subnet mask? Answer:
  | Binary | Dotted Decimal |
---|---|---|
Address | 10000011.00000101.11111100.00010011 | 131.5.252.19 |
Subnet Mask | 11111111.11111111.11111110.00000000 | 255.255.254.0 |
Subnet Address | 10000011.00000101.11111100.00000000 | 131.5.252.0 |
How many host addresses are there on the subnet? Answer: 29 = 512.
What is the range of host addresses for this
subnet. Ans: The bits in the address that correspond to a 1 in the subnet mask
are fixed, but the bits in the address that correspond to a 0 in the subnet
mask are free to vary. The smallest possible value is to make all the bits
that are free to vary 0. The largest value is to make all the bits that are
free to vary 1. Hence the smallest value is
10000011.00000101.11111100.00000000
= 131.5.252.0
and the largest value is
10000011.00000101.11111101.11111111
= 131.5.253.255
Input 1 | Input 2 | Result |
---|---|---|
0 | 0 | 0 |
0 | 1 | 0 |
1 | 0 | 0 |
1 | 1 | 1 |
The bitwise And operation on two binary values is computed by performing an And operation on corresponding bits in parallel:
11001001
10011011
========
10001001
Here is how it can be broken down:
Column | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
Input 1 | 1 | 1 | 0 | 1 | 1 | 0 | 1 | 1 |
Input 2 | 1 | 0 | 0 | 1 | 1 | 0 | 1 | 1 |
Result | 1 | 0 | 0 | 0 | 1 | 0 | 0 | 1 |
Notice that in Examples 1 and 2, the network address equals the bitwise and of the host address with the subnet mask.
Suppose that these are the entries in an example routing table.
Subnet Mask | Network Address | Next Hop Address |
---|---|---|
255.255.255.240 | 192.17.7.208 | 192.12.7.15 |
255.255.255.240 | 192.17.7.144 | 192.12.7.67 |
255.255.255.0 | 192.17.7.0 | 192.12.7.251 |
0.0.0.0 | 0.0.0.0 | 192.17.7.1 |
Suppose the router receives an IP packet with the destination address 192.17.7.164. Here is how the next hop address is determined.
Step 1. Compute the bitwise and of the destination address and the subnet mask. If the result is equal to network address in that row of the routing table, a match is found and the packet is forwarded to the next hop address in that row. If no match is found, the process is continued with the next row in the routing table.
  | Dotted Decimal | Binary |
---|---|---|
Destination Address | 192.17.7.164 | 11000000.00010001.00000111.10100100 |
Subnet Mask | 255.255.255.240 | 11111111.11111111.11111111.11110000 |
Result | 192.17.7.160 | 11000000.00010001.00000111.10100000 |
Network Address | 192.17.7.144 | 11000000.00010001.00000111.10010000 |
The result and the network address do not match, so continue to Step 2 where we repeat the same procedure with the second row of the routing table. Step 2.
  | Dotted Decimal | Binary |
---|---|---|
Destination Address | 192.17.7.164 | 11000000.00010001.00000111.10100100 |
Subnet Mask | 255.255.255.240 | 11111111.11111111.11111111.11110000 |
Result | 192.17.7.160 | 11000000.00010001.00000111.10100000 |
Network Address | 192.17.7.208 | 11000000.00010001.00000111.11010000 |
Again there is no match, so we continue to Step 3.
Step 3.
  | Dotted Decimal | Binary |
---|---|---|
Destination Address | 192.17.7.164 | 11000000.00010001.00000111.10100100 |
Subnet Mask | 255.255.255.0 | 11111111.11111111.11111111.00000000 |
Result | 192.17.7.0 | 11000000.00010001.00000111.00000000 |
Network Address | 192.17.7.0 | 11000000.00010001.00000111.00000000 |
Now the result and the network address match, so the packet is forwarded to the next hop address 192.12.7.251.
Notice that we will always have a match for the last row of the above routing table. Why?
Other fields in a more realistic routing table include
Open Shortest Path First (OSPF). This algorithm is currently gaining in popularity. Rather than only trying to minimize the hop count, it also takes into account information like throughput and delay for each hop. A router only shares its information with its neighbors when a change occurs, this reducing network traffic.
Border Gateway Protocol (BGP). We wont go into the details of BGP here. Whereas RIP and OSPF are designed for intranetwork traffic (traffic within a network controled by a single organization), BGP is designed for internetwork traffic (traffic between networks). RIP and OSPF are not efficient for internetwork traffic because computing the shortest path is not efficient for very large networks.
Query | MAC Sender Address | IP Sender Address |                                   | IP Target Address |
The target host recognizes its IP address in the ARP packet, fills in its MAC Address, and changes the first field to Answer, and sends the ARP packet back:
Answer | MAC Sender Address | IP Sender Address | MAC Target Address | IP Target Address |
The router receives the answer, then encapsulates the original IP packet as an Ethernet frame, and forwards it to the target host.