IPv4: Internet Protocol Version 4
IPv4 is the fourth version of the Internet Protocol (IP) and is the first version that has been widely deployed. It is the primary protocol used for routing traffic across the internet. This document provides an in-depth look at IPv4, its structure, addressing, and common concepts.
What is IPv4?
IPv4 is a network layer protocol that provides a unique logical address for each device connected to a network. This addressing scheme allows devices to communicate with each other across different networks, forming the foundation of the internet.
IPv4 Address Structure
An IPv4 address is a 32-bit number, typically represented in dotted-decimal notation. This notation consists of four octets (8-bit numbers), each ranging from 0 to 255, separated by dots. For example:
192.168.1.1
Each octet can be represented in binary as 8 bits:
11000000.10101000.00000001.00000001
Key Components of an IPv4 Address
- Network Portion: Identifies the specific network to which the device belongs.
- Host Portion: Identifies the specific device (host) within that network.
The division between the network and host portions is determined by the subnet mask.
Subnet Masks
A subnet mask is also a 32-bit number that works in conjunction with an IP address to separate the network address from the host address. It uses a contiguous sequence of 1s followed by a contiguous sequence of 0s. The 1s indicate the network portion, and the 0s indicate the host portion.
Common subnet masks:
255.255.255.0
(/24
CIDR notation): First three octets are network, the last is host.255.255.0.0
(/16
CIDR notation): First two octets are network, the last two are host.255.0.0.0
(/8
CIDR notation): The first octet is network, the last three are host.
The corresponding IP address and subnet mask are used to calculate the network address using a bitwise AND operation.
IP Address Classes (Historical Context)
Historically, IPv4 addresses were divided into classes (A, B, C, D, E) based on the first octet. While less relevant with modern CIDR, understanding these can be helpful:
- Class A:
1.0.0.0
to126.255.255.255
(Default mask:255.0.0.0
) - Class B:
128.0.0.0
to191.255.255.255
(Default mask:255.255.0.0
) - Class C:
192.0.0.0
to223.255.255.255
(Default mask:255.255.255.0
) - Class D:
224.0.0.0
to239.255.255.255
(Multicast addresses) - Class E:
240.0.0.0
to255.255.255.255
(Reserved for future use)
Note: 127.x.x.x
is reserved for loopback.
Special IPv4 Addresses
- Loopback Address:
127.0.0.1
(Used for testing network interfaces) - Private IP Addresses: Blocks of addresses reserved for use within private networks (e.g.,
192.168.x.x
,10.x.x.x
,172.16.x.x
to172.31.x.x
). These are not routable on the public internet. - Broadcast Address: The last address in a subnet (all host bits set to 1), used to send data to all hosts on that subnet.
- Multicast Addresses: Used for one-to-many communication.
IP Packet Structure
When data is sent over IPv4, it is encapsulated in an IP packet. The header of an IPv4 packet contains crucial information for routing and delivery:
Version (4 bits)
Internet Header Length (IHL) (4 bits)
Differentiated Services Code Point (DSCP) (6 bits)
Explicit Congestion Notification (ECN) (2 bits)
Total Length (16 bits)
Identification (16 bits)
Flags (3 bits)
Fragment Offset (13 bits)
Time to Live (TTL) (8 bits)
Protocol (8 bits)
Header Checksum (16 bits)
Source IP Address (32 bits)
Destination IP Address (32 bits)
Options (Variable)
Padding (Variable)
CIDR (Classless Inter-Domain Routing)
CIDR has largely replaced the old classful addressing scheme. It allows for more flexible allocation of IP addresses by using a prefix length (e.g., /24
) to denote the network portion of an IP address, regardless of its class. This enables efficient subnetting and supernetting.
Challenges and Limitations
The primary limitation of IPv4 is its finite address space. With the explosion of internet-connected devices, the 4.3 billion available IPv4 addresses are nearly exhausted. This has led to the development and adoption of IPv6.