# IPv4 Addressing
## What is IPv4
IPv4, or Internet Protocol version 4, is the fourth version of the Internet Protocol and the first version to be widely deployed. It has been the dominant protocol for internet communication since the early 1980s. IPv4 uses 32-bit addresses, written in dotted decimal notation as four octets separated by dots, such as 192.168.10.1. The 32-bit address space provides approximately 4.3 billion unique addresses. Although this seemed sufficient when IPv4 was designed, the massive growth of the internet has led to the exhaustion of available IPv4 addresses.
## IPv4 Address Format
Each IPv4 address is 32 bits long, divided into four groups of 8 bits called octets. Each octet is written as a decimal number between 0 and 255. The address 11000000.10101000.00000001.00000001 in binary is written as 192.168.1.1 in dotted decimal notation. Every bit in an IPv4 address is either a 0 or a 1. The leftmost bit is the most significant bit and the rightmost bit is the least significant bit. Converting between binary and decimal is an essential skill for understanding subnetting and IP addressing.
## Network and Host Portions
An IPv4 address is divided into two logical parts by the subnet mask. The network portion identifies the network to which the device belongs. The host portion identifies the specific device within that network. All devices on the same network share the same network portion of their IP address but have different host portions. When a router receives a packet, it extracts the network portion of the destination IP address by applying the subnet mask, then looks up that network in its routing table to determine where to forward the packet.
## Special IPv4 Addresses
Certain IPv4 addresses are reserved for special purposes and cannot be assigned to individual hosts. The network address is the first address in a subnet where all host bits are zero. It identifies the network itself and cannot be assigned to a device. The broadcast address is the last address in a subnet where all host bits are one. Packets sent to the broadcast address are delivered to all hosts on the subnet. The loopback address is 127.0.0.1, used by a device to send packets to itself for testing the network stack. The addresses 169.254.0.0 to 169.254.255.255 are link-local addresses automatically assigned to a device when it cannot obtain an address from a DHCP server.
## Private IPv4 Addresses
Three ranges of IPv4 addresses are designated as private. These addresses are not routable on the public internet and can be used by any organization for its internal network without registration. The Class A private range is 10.0.0.0 to 10.255.255.255. The Class B private range is 172.16.0.0 to 172.31.255.255. The Class C private range is 192.168.0.0 to 192.168.255.255. Private addresses are used in homes and organizations for their internal devices, with NAT translating between private and public addresses at the border router.
## IPv4 Header
The IPv4 header contains important fields that control how the packet is processed. The version field identifies this as an IPv4 packet. The header length field specifies the length of the header. The total length field specifies the total length of the packet including header and data. The time to live field is decremented by each router and the packet is discarded when it reaches zero, preventing packets from circulating indefinitely. The protocol field identifies the Transport layer protocol carried in the packet, such as 6 for TCP or 17 for UDP. The source IP address and destination IP address are 32 bits each and identify the sender and intended recipient.
## IPv4 Exhaustion
The Internet Assigned Numbers Authority allocated the last block of IPv4 addresses in 2011. Regional internet registries subsequently exhausted their allocations. The industry has responded with short-term measures including NAT, which allows many devices to share a single public IP address, and more efficient allocation practices. The long-term solution is migration to IPv6, which provides a vastly larger address space.Back to Subject