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

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:

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:

Note: 127.x.x.x is reserved for loopback.

Special IPv4 Addresses

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.