Even if only two point-to-point devices are connected via TCP/IP, the address structure of the lower layers needs to be implemented in addition to implementing the IP (Internet Protocol) protocol. On this occasion the structure of a TCP/IP network, IP addressing and network classes will be explained.
To understand the operation of a router you can make a simile to the old switching telephone exchanges. Each device was wired to the nearest exchange and the communication was made point-to-point. If you wanted to make a call to a device connected to the same central you had to make a "bridge" or direct connection between the two devices having a direct path from device to device, also known as end-to-end or point-to-point. If you wanted to make a call to a device outside the central, you had to find the shortest path connecting from one exchange to another until you reach the central destination and once there make a bridge to the target device.
Until recently, telephone communications followed the same principle, although they have evolved. Thanks to the automation they have changed the pins by relays and these by transistors. Today, there are no longer any switching centers, now VoIP protocols are used and all conversations are transmitted through a network composed of several routers that guide the packets from the origin to the destination without going through any relay.
A Router has the ability to forward a packet to other routers and, therefore, to other networks. Between two devices connected to a network can be several paths and the router's mission is to decide which one to send the packet depending on the destination and the state of the network.
There is no guarantee that two packages will travel the same way although they have the same address of origin and destination. For this reason, packets can arrive messy or even not arrive if one of the routers fails. The positive part is that the TCP/IP protocol in its upper layers is able to correct these setbacks and also treat the redundancy thanks to the numbering of the packets.
If a software is made using a high-level TCP/IP library, the data is transparent and you do not have to worry about how the devices are connected or what networks they belong to, since the router is responsible for checking and resending the packet if it has as an external network destination or send it to a device connected to it if the destination is on the same network.
Each device connected to the network must have a unique address. In IPv4, 4-byte IP addresses are used separated by a point after each byte. The format expressed in decimal values would be XXX.XXX.XXX.XXX, four groups of numbers from 0 to 255, for example, 220.127.116.11 is an IP address.
In an internal network, any IP can be used but to connect to the Internet network, the IPs are regulated and assigned by the ICANN (Internet Corporation for Assigned Names and Numbers).
An IP address consists of 3 different parts:
- NetID. Number that identifies a large network.
- SubnetID. It is the identifier of a subnet within the network.
- DeviceID. To identify the devices within the subnet.
The size of these fields varies depending on the size of the network and subnets that you want to create as well as the number of devices that you want to connect.
IP addresses are divided into classes depending on the number of bytes representing the network.
A Class A. In a network of this type, the most significant byte, the one on the left, represents the network and the most significant bit (the one on the left) has the value of 0, which means that there are a total of 128 possibilities. From 0 to 127 but it should consider that network 0 does not exist and number 127 is reserved to indicate the local computer, so that a total of 126 different networks can be created. From 18.104.22.168 to 22.214.171.124 with a total of 16,777,214 connected devices. In binary, a type A network can be seen as follows:
Byte 0 Byte 1 Byte 2 Byte 3 0XXXXXXX XXXXXXXX XXXXXXXX XXXXXXXX Network Devices
B Class. In this type, the network is represented by the two most significant bytes, the two bytes on the left and the first two bits have the value of "10" so that a total of 16,384 different networks can be created with a total of 65,534 connected devices. The networks range from 126.96.36.199 to 188.8.131.52. In binary a type B network can be seen in the following way:
Byte 0 Byte 1 Byte 2 Byte 3 10XXXXXX XXXXXXXX XXXXXXXX XXXXXXXX Network Devices
C Class. In a network of this type the network is represented with the 3 most significant bytes and the first 3 bits have the value of "110" so that a total of 2,097,152 of networks with 254 devices each can be had. The networks range from 192.0.0.0 to 253.255.255.0 and in binary they can be seen as follows:
Byte 0 Byte 1 Byte 2 Byte 3 110XXXXX XXXXXXXX XXXXXXXX XXXXXXXX Network Devices
For example, network 184.108.40.206 contains devices with IP addresses ranging from 220.127.116.11 to 18.104.22.168. The network can be written 193.151.90 and each device must be listed sequentially from 1 to 254.
The reason why the networks are divided is to find the destination easily because in this way the network is checked first and then the device is searched and this task is performed with an AND logical operation that will be explained in the next article.