What is Internet Protocol (IP)?

In this tutorial, you will learn the basic concepts of Internet Protocol (IP). After reading this tutorial, you will know the types, versions, header packets, subnetting, and need of IP addresses.

Contents:

  1. Internet Protocol (IP)
  2. IPv4 Addressing
  3. Prefix Length in IPv4 Address
  4. Public, Private, and Special Use IPv4 Addresses
  5. Classful Addressing
  6. Need For IPv6 Addresses
  7. IPv6 Addressing
  8. Types of IPv6 Addresses

Internet Protocol (IP)

As we know that there are many devices present on a network. But how are they connected to each other, what do they use to communicate with another device? For that, they have a unique number known as an IP address which is used to hold the entire Internet together.

  • Generally, Internet Protocol is the primary protocol of the network layer. It uses a best-effort mechanism to transport packets from source to destination.
  • In a network, IP provides only those functions which are required to send packets from source to destination.
  • IP does not care whether the network is wired or wireless. It cares about the delivery of packets. Also, it does not guarantee that the packets sent by the sender will be received correctly by the receiver.
  • IP does not track and maintain the flow of packets.
  • On the sender side, when the network layer receives the segment from the transport layer, it adds the IP header to the segment and forms the packet. Then, the sender sends the packet to the receiver.
  • When the receiver receives the packet, its network layer forwards the packet to the transport layer, and the transport layer decides to which process the packet should be assigned.
  • Basically, there are two versions of IP, one is IPv4 (IP version-4), and the other is IPv6 (IP version-6).

The figure below shows IPv4 and IPv6 packet header or datagram.

IPv4 and IPv6 Packet Header
  • As shown in the figure, Version, Differentiated Services (DS), Header Checksum, Time to Live (TTL), Protocol, and Source and Destination IPv4 Address are the fields of an IPv4 packet.
  • Version, Traffic Class, Flow Label, Payload Length, Next Header, Hop Limit, and Source and Destination IPv6 addresses are the fields of an IPv6 packet.

IPv4 Addressing

advertisement
advertisement

An IPv4 address is 32-bit number which means that there are a total of 232 (4,294,967,296) IPv4 addresses. Here 4 means there are 4 octets separated by a dot. IPv4 consists of two portions, a network portion and a host portion.

The figure below shows the structure of an IPv4 address.

Structure of an IPv4 Address
  • As shown in the figure, the IPv4 address consists of a network and a host portion. The size of the network and host portion varies by network.
  • In our case, 24 bits belong to the network portion, and the remaining 8 bits belong to the host portion. The network portion is the same for all the devices residing in the same network.
  • Each device on the network has a unique IPv4 address.

Subnet Mask: When a device receives a unique IPv4 address, it has a subnet mask that separates the network and host portions of the IPv4 address. Using the subnet mask, the router determines the network address of the device.

  • The subnet mask guides the router to know how long the network portion is. The network portion and the host portion can be identified by the AND method.
  • In logical AND, the result is 1 if both the bits have the value 1. The possible results of AND operation are given below:
    • 0 AND 0 = 0
    • 0 AND 1 = 0
    • 1 AND 0 = 0
    • 1 AND 1 = 1

The figure below shows the AND operation between an IPv4 address and a subnet mask.

AND Operation between Host IPv4 Address and Subnet Mask
  • As shown in the figure, the host IP is 192.168.10.25, and the subnet mask is 255.255.255.0. The host IP and subnet mask are converted to binary.
  • Now, the AND operation is performed between 192.168.10.25 and 255.255.255.0, which gives 192.168.10.0 as the result.
  • 192.168.10.0 is the network address of 192.168.10.25 address.

IP Addresses: There are three types of IP addresses: network address, host address, and broadcast address.

The below diagram explains the IP Addresses.

Types of IPv4 Addresses
  • Network address: The network address represents a unique address in which multiple devices exist along with the host IP address. In our case, 200.12.1.0/24 is the network address.
    • A device belongs to the 200.12.1.0 network if its subnet is the same as the network address.

  • Host Address: Host addresses are assigned to each device. This is unique to each device. The 200.12.1.0 network has a total of 256 IPs which range from 200.12.1.0-200.12.1.255.
    • The first address 200.12.1.0 is used for the network address. The last address 200.12.1.255 is used as the broadcast address.
    • The addresses from 200.12.1.1to 200.12.1.254 are used as host addresses. Out of 256 IP addresses, 254 addresses are used as host addresses.

  • Broadcast Address: The last address of the network is used as the broadcast address. Generally, it is used to broadcast packets.
    • In a broadcast address, the host bits are all 1. In our example, 200.12.1.255/24 is the broadcast address.

Prefix Length in IPv4 Address

advertisement

We can identify the subnets of IPv4 by using the prefix length. In IP address subnet mask, number of bits set to 1 is called the prefix length.

The diagram below shows the prefix length of an IPv4 address.

IPv4 Address Prefix Length
  • As shown in the figure, the subnet mask is first written in binary format. The number of 1 bit is known as the prefix bit.
  • Basically, the prefix length of the subnet mask is written after the slash notation.
  • Instead of writing like 192.156.12.3 255.255.255.0, the IPv4 address is written as 192.156.12.3/24. Here /24 is 255.255.255.0.

Public, Private, and Special Use IPv4 Addresses

The network layer transmits IPv4 packets in different ways. Some specific IP addresses are used to navigate the Internet, while others are allocated for routing over the Internet.

  • Public IP Address: Public IP addresses are global, which means that these IP addresses are assigned to any device on the global network.
  • Private IP Address: Private IP addresses are mostly used by organizations. Private IP addresses are allocated to organizations so that communication can take place only in that range of private IP addresses. Basically, the private IPv4 address is not unique. It is used in the internal network.
    • Generally, router didn’t communicate using private IP address. It uses network address translation (NAT) to translate the private IP address to the public IP address.

The below diagram shows the private IPv4 addresses block.

private IPv4 addresses block
  • As shown in the figure, 10.0.0/8, 172.16.0.0/12, and 192.168.0.0/16 are the private addresses used for the internal network.
advertisement

Special Use IPv4 Addresses: Loopback addresses and Link-Local addresses are the special use IPv4 addresses.

  • Loopback Addresses: Loopback addresses are used when the host wants to send traffic to itself. Addresses ranging from 127.0.0.0/8 or 127.0.0.1 to 127.255.255.254 are known as loopback addresses.
  • Link-Local Addresses: When the device does not get an IP dynamically, it is assigned one of the link-local addresses. It is also known as Automatic Private IP Addressing (APIPA) or Self-Assigned Address.
    • Link-Local Addresses are 169.254.0.0/16 or 169.254.0.1 to 169.254.255.254.

Classful Addressing

IPv4 addresses are divided into five classes that are A, B, C, D, and E. Each class has a different number of IPv4 addresses. By looking at the first byte of the IP address, we can determine the class of the IP address.

The below diagram explains classful addressing.

Classful IPv4 Addresses
  • As shown in the figure, class-A IP addresses range from 0 (0.0.0.0/8) to 127 (127.0.0.0/8). Similarly, Class-B, Class-C, Class-D and Class-E IP addresses range from 128 (128.0.0.0/16) to 191 (191.255.0.0/16), 192 (192.0.0.0/24) to 223 (223.255.255.0/24), 224 (224.0.0.0) to 239 (239.0.0.0), and 240 (240.0.0.0) to 255 (255.0.0.0), respectively.
  • It also shows that, as the subnet mask increases, the number of host decreases.

The below diagram explains the calculation of hosts in an IP address.

Host IPv4 Address Calculation
  • As shown in the figure, the IP address 192.168.12.0 has the /24 subnet mask. The first 24 bits belong to the network portion, and the remaining 8 bits (32-24 = 8) belong to the host part.
  • So the total number of hosts for 192.168.12.0 IP address is,
    • Number of hosts = 28 – 2
    • Number of hosts = 256 – 2
    • Number of hosts = 254
    • Here (-2) indicates that the first address of IP 192.168.12.0/24 defines the 192.168.12.0 network IP and the last IP of 192.168.12.0/24 defines the 192.168.12.255 broadcast address. Both are reserved addresses.

Need For IPv6 Addresses

As we know that the population of the world is increasing and the number of devices on the internet is also increasing. Because of this, IPv4 addresses are running out, as they have a total of 4.2 billion IP addresses. So IPv6 is in trend, and it is the successor of IPv4. IPv4 has 32bit address space, whereas IPv6 has 128-bit address space, which means there are 2128 IPv6 addresses available.

  • The IETF (Internet Engineering Task Force) developed IPv6 to correct the limitations of IPv4 because there are not enough IPv4 addresses to accommodate the development.
  • There exist some protocols which are used by the network administrator if he wants to migrate his IPv4 address network to the IPv6 address network.
  • The tunneling method is used to transport IPv6 packets over an IPv4 network because the IPv6 packet is encapsulated in an IPv4 packet.
  • It is also possible on the network that a device that has an IPv6 address can communicate with a device with an IPv4 address using the NAT64 (Network Address Translation 64) method.

IPv6 Addressing

In an IPv6 address, there are 8 sections separated by colons (:), with 16 bits in each section. Let us understand the format of the IPv6 address.

The figure below shows the format of an IPv6 address.

format of an IPv6 address
  • As shown in the figure, 2001:0db8:0001:1111:0011:1010:fe9a:12ab is an example of an IPv6 address.
  • As you can see, there are 8 segments of 16 bit, or you can call it Hextets.

Certain rules are used to shorten IPv6 addresses. They are as follows:

  • Rule 1: Omit the leading zero of the IPv6 address. In this rule, to shorten the notation of IPv6, omit the leading zero in any hextet.
  • Rule 2: In this rule, the double colon (::) replaces any single, continuous string of one or 16-bit hextets containing all zeros.

The figure below explains the two rules for IPv6 address shortening.

Rules to Shorten the IPv6 Address
  • As shown in the figure, 2001:0011:0101:11AA:0AB3:0000:0000:123A is an IPv6 address. In the first rule, leading zeros is omitted and the resulting shorten IPv6 address becomes 2001:11:101:11AA:AB3:0:0:123A.
  • Now, as a second rule, replace the continuous string containing zeros with a single colon, as shown in the figure. 2001:11:101:11AA:AB3:0:0:123A becomes 2001:11:101:11AA:AB3::123A.
  • If there is more than one continuous string of all-0 hextets, use a double colon (::) on the longest string.

IPv6 Prefix Length: In IPv4, we identify the network portion by looking at the subnet mask. Similarly, in an IPv6 address, the address is divided into two 64-bit portions.

  • The first 64 bit portion is known as the prefix, and the remaining 64 bit portion is known as the interface ID.

The below diagram explains the prefix length in IPv6 address.

prefix length in IPv6 address

As shown in the figure, the IP address 2001:0DB8:0101:11AA:23AD:0001:1000:EF2W is an IPv6 address. In which the first 64 bits (2001:0DB8:0101:11AA) define the prefix and the remaining 64 bits (23AD:0001:1000:EF2W) define the interface ID.

Types of IPv6 Addresses

Unicast IPv6 addresses and Multicast IPv6 addresses are the types of IPv6 (IP – version 6) addresses. IPv6 unicast addresses are used to identify the interface of a device on a network. IPv6 multicast addresses are used when a packet needs to be sent to multiple devices.

IPv6 Unicast Addresses: Global unicast, link-local, loopback, unspecified and unique local addresses are IPv6 unicast addresses.

  • Global Unicast Address (GUA): GUA is similar to a public IPv4 address in that it is globally unique to the specific device, which can be assigned statically or dynamically. The range of GUA is from 2000::/3 to 3fff::/3.
    • In GUA, the first 48 bits are known as the Global Routing Prefix, the middle 16 bits are known as the Subnet ID, and the remaining 64 bits are known as the Interface ID.

  • Link-Local Address (LUA): This address is used when two devices are on the same link and is required for each device that has an IPv6 GUA address. Routers do not forward packets using LUA packets. They only send packets using GUA addresses.
    • LLAs are in the range of fe80::/10.
    • The router sends routing updates to its neighboring routers using a link-local address. The host device uses the router’s link-local address as the default gateway.

  • Unique Local Address: This address can be used if the device should not be accessible from an external network. Furthermore, it cannot be translated into IPv6 public addresses.
    • They are in the range fc00::/7 to fdff::/7.
  • Loopback Address: The loopback address is the IPv6 address of the device local-host. It is ::1/128. The device uses a loopback address if it wants to send packets to itself.
  • Unspecified Address: As the name suggests IPv6 address is unspecified. Unspecified IPv6 address format is ::.

IPv6 Multicast Address: IPv6 multicast addresses are the same addresses as IPv4 multicast addresses. It is used to send a packet from one source to multiple destinations. In the IPv6 multicast address, the prefix for a multicast address is ff00::/8.

  • Well-known and Solicited node addresses are the types of IPv6 Multicast Addresses.
  • Well-known IPv6 Multicast Addresses: Well-known IPv6 Multicast addresses are reserved for pre-defined groups of devices.

    • The ff02::1 and ff02::2 address groups are used for multicast purposes. If packets sent by the device are to be received by each IPv6 capable end device, the ff02::1 address is used. It is also known as an all-nodes multicast group.
    • If a packet is to be sent and processed by each IPv6-enabled router, the ff02::2 multicast address is used. This address is also known as an all-router multicast group.
  • Solicited-Node IPv6 Multicast Addresses: This address is used by the Ethernet NIC to filter packets. If a sender sends a packet to 3 destinations, the destination Ethernet NIC decides whether this packet sent by the sender is for me or not.

Key Points to Remember

Here is the list of key points we need to remember about “Internet Protocol (IP)”.

  • Internet Protocol is the primary protocol of the network layer. It uses a best-effort mechanism to transport packets from source to destination.
  • IP does not track and maintain the flow of packets. There are two versions of IP, one is IPv4 (IP version-4), and the other is IPv6 (IP version-6).
  • An IPv4 address is 32 bit number which means that there are a total of 232 (4,294,967,296) IPv4 addresses. IPv4 consists of a network portion and a host portion.
  • When a device receives a unique IPv4 address, it has a subnet mask that separates the network and host portions of the IPv4 address. Using the subnet mask, the router determines the network address of the device.
  • There are three types of IP addresses: network address, host address, and broadcast address.
  • IPv4 addresses are divided into five classes that are A, B, C, D, and E. Each class has a different number of IPv4 addresses. By looking at the first byte of the IP address, we can determine the class of the IP address.
  • The IETF (Internet Engineering Task Force) developed IPv6 to correct the limitations of IPv4 because there are not enough IPv4 addresses to accommodate the development.
  • Global unicast, link-local, loopback, unspecified and unique local addresses are IPv6 unicast addresses.

If you find any mistake above, kindly email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.