Internet Protocol version 4 (IPv4) is the fourth revision in the development of the Internet Protocol (IP) and it is the first version of the protocol to be widely deployed. Together with IPv6, it is at the core of standards-based internetworking methods of the Internet, and is still by far the most widely deployed Internet Layer protocol.
IPv4 is a data-oriented protocol to be used on a packet switched internetwork (e.g., Ethernet). It is a best effort delivery protocol in that it does not guarantee delivery, nor does it assure proper sequencing, or avoid duplicate delivery. These aspects are addressed by an upper layer protocol (e.g. TCP, and partly by UDP). IPv4 does, however, provide data integrity protection through the use of packet checksums.
IPv4 uses 32-bit (four-byte) addresses, which limits the address space to 4,294,967,296 (232) possible unique addresses. However, some are reserved for special purposes such as private networks (~18 million addresses) or multicast addresses (~16 million addresses). This reduces the number of addresses that can be allocated as public Internet addresses. As the number of addresses available are consumed, an IPv4 address shortage appears to be inevitable, however network address translation (NAT) has significantly delayed this inevitability.
This limitation has helped stimulate the push towards IPv6, which is currently in the early stages of deployment and the only contender to replace IPv4.
IPv4 addresses are usually written in dot-decimal notation, which consists of the four octets of the address expressed in decimal and separated by periods. This is the base format used in the conversion in the following table:
|Notation||Value||Conversion from dot-decimal|
|Dotted Hexadecimal||Each octet is individually converted to hexadecimal form|
|Dotted Octal||Each octet is individually converted into octal|
|Hexadecimal||Concatenation of the octets from the dotted hexadecimal|
|Decimal||The 32-bit number expressed in decimal|
|Octal||The 32-bit number expressed in octal|
Most of these formats should work in all browsers. Additionally, in dotted format, each octet can be of any of the different bases. For example,
192.0x00.0002.235 is a valid (though unconventional) equivalent to the above addresses.
A final form is not really a notation since it is rarely written in an ASCII string notation. That form is a binary form of the hexadecimal notation in binary. This difference is merely the representational difference between the string "0xCF8E83EB" and the 32-bit integer value 0xCF8E83EB. This form is used for assigning the source and destination fields in a software program.
Originally, an IP address was divided into two parts:
This created an upper limit of 256 networks. As the networks began to be allocated, this was soon seen to be inadequate.
To overcome this limit, different classes of network were defined, in a system which later became known as classful networking.Five classes were created (A, B, C, D, and E), three of which (A, B, and C) had different lengths for the network field. The rest of an address was used to identify a host within a network, which meant that each network class had a different maximum number of hosts. Thus there were a few networks with each having many host addresses and numerous networks with each only having a few host addresses.Class D was for multicast addresses and Class E was reserved.
Around 1993, these classes were replaced with a Classless Inter-Domain Routing (CIDR) scheme, and the previous scheme was dubbed "classful", by contrast.CIDR's primary advantage is to allow re-division of Class-A, -B and -C networks so that smaller (or larger) blocks of addresses may be allocated to various entities (such as Internet service providers, or their customers) or local area networks.
The actual assignment of an address is not arbitrary. The fundamental principle of routing is that the address of a device encodes information about the device's location within a network. This implies that an address assigned to one part of a network will not function in another part of the network. A hierarchical structure, created by CIDR and overseen by the Internet Assigned Numbers Authority (IANA) and its Regional Internet Registries (RIRs), manages the assignment of Internet addresses worldwide. Each RIR maintains a publicly-searchable WHOIS database that provides information about IP address assignments; information from these databases plays a central role in numerous tools that attempt to locate IP addresses geographically.
|CIDR address block||Description||Reference|
|0.0.0.0/8||Current network (only valid as source address)||RFC 1700|
|10.0.0.0/8||Private network||RFC 1918|
|22.214.171.124/8||Public data networks (per 2008-02-10, available for use)||RFC 1700|
|126.96.36.199/16||Reserved (IANA)||RFC 3330|
|172.16.0.0/12||Private network||RFC 1918|
|188.8.131.52/16||Reserved (IANA)||RFC 3330|
|192.0.0.0/24||Reserved (IANA)||RFC 3330|
|192.0.2.0/24||Documentation and example code||RFC 3330|
|184.108.40.206/24||IPv6 to IPv4 relay||RFC 3068|
|192.168.0.0/16||Private network||RFC 1918|
|198.18.0.0/15||Network benchmark tests||RFC 2544|
|220.127.116.11/24||Reserved (IANA)||RFC 3330|
|18.104.22.168/4||Multicasts (former Class D network)||RFC 3171|
|240.0.0.0/4||Reserved (former Class E network)||RFC 1700|
See main article: private network. Of the four billion addresses allowed in IPv4, three ranges of address are reserved for private networking use.These ranges are not routable outside of private networks and private machines cannot directly communicate with public networks.They can, however, do so through network address translation.
The following are the three ranges reserved for private networks (RFC 1918):
|Name||Address range||Number of addresses||Classful description||Largest CIDR block|
|24-bit block||10.0.0.0–10.255.255.255||16,777,216||Single Class A||10.0.0.0/8|
|20-bit block||172.16.0.0–172.31.255.255||1,048,576||16 contiguous Class B blocks||172.16.0.0/12|
|16-bit block||192.168.0.0–192.168.255.255||65,536||Contiguous range of 256 class C blocks||192.168.0.0/16|
RFC 3330 defines an address block, 169.254.0.0/16, for the special use in link-local addressing. These addresses are only valid on the link, such as a local network segment or point-to-point connection, that a host is connected to. These addresses are not routable and like private addresses cannot be the source or destination of packets traversing the Internet. Link-local addresses are primarily used for address autoconfiguration (Zeroconf) when a host cannot obtain an IP address from a DHCP server or other internal configuration methods.
When the address block was reserved, no standards existed for mechanisms of address autoconfiguration. Filling the void, Microsoft created an implementation that called Automatic Private IP Addressing (APIPA). Due to Microsoft's market power, APIPA has been deployed on millions of machines and has, thus, become a de facto standard in the industry. Many years later, the IETF defined a formal standard for this functionality, RFC 3927, entitled Dynamic Configuration of IPv4 Link-Local Addresses.
The address range 127.0.0.0–127.255.255.255 (127.0.0.0/8 in CIDR notation) is reserved for localhost communication.Addresses within this range should never appear outside a host computer and packets sent to this address are returned as incoming packets on the same virtual network device (known as loopback).
See main article: IPv4 subnetting reference. It is a common misunderstanding that addresses ending in 255 or 0 can never be assigned to hosts. This is only true of networks with subnet masks of at least 24 bits — Class C networks in the old classful addressing scheme, or in CIDR, networks with masks of /24 to /32 (or 255.255.255.0–255.255.255.255).
In classful addressing (now obsolete with the advent of CIDR), there are only three possible subnet masks: Class A, 255.0.0.0 or /8; Class B, 255.255.0.0 or /16; and Class C, 255.255.255.0 or /24. For example, in the subnet 192.168.5.0/255.255.255.0 (or 192.168.5.0/24) the identifier 192.168.5.0 refers to the entire subnet, so it cannot also refer to an individual device in that subnet.
A broadcast address is an address that allows information to be sent to all machines on a given subnet, rather than a specific machine. Generally, the broadcast address is found by obtaining the bit complement of the subnet mask and performing a bitwise OR operation with the network identifier. In other words, the broadcast address is the last address in the range belonging to the subnet. In our example, the broadcast address would be 192.168.5.255, so to avoid confusion this address also cannot be assigned to a host. On a Class A, B, or C subnet, the broadcast address always ends in 255.
However, this does not mean that every addresses ending in 255 cannot be used as a host address. For example, in the case of a Class B subnet 192.168.0.0/255.255.0.0 (or 192.168.0.0/16), equivalent to the address range 192.168.0.0–192.168.255.255, the broadcast address is 192.168.255.255. However, one can assign 192.168.1.255, 192.168.2.255, etc. (though this can cause confusion). Also, 192.168.0.0 is the network identifier and so cannot be assigned, but 192.168.1.0, 192.168.2.0, etc. can be assigned (though this can also cause confusion).
With the advent of CIDR, broadcast addresses do not necessarily end with 255.
In general, the first and last addresses in a subnet are used as the network identifier and broadcast address, respectively. All other addresses in the subnet can be assigned to hosts on that subnet.
See main article: Domain Name System. Hosts on the Internet are usually known not by IP addresses, but by names (e.g., www.wikipedia.org, www.whitehouse.gov, www.freebsd.org, www.berkeley.edu).The routing of IP packets across the Internet is not directed by such names, but by the numeric IP addresses assigned to such domain names. This requires translating (or resolving) domain names to addresses.
The Domain Name System (DNS) provides such a system for converting names to addresses and addresses to names.Much like CIDR addressing, the DNS naming is also hierarchical and allows for subdelegation of name spaces to other DNS servers.
The domain name system is often described in analogy to the telephone system directory information systems in which subscriber names are translated to telephone numbers.
See main article: IP address exhaustion. Since the 1980s it has been apparent that the number of available IPv4 addresses is being exhausted at a rate that was not initially anticipated in the design of the network. This was the driving factor for the introduction of classful networks, for the creation of CIDR addressing, and finally for the redesign of the Internet Protocol, based on a larger address format (IPv6).
Today, there are several driving forces for the acceleration of IPv4 address exhaustion:
The accepted and standardized solution is the migration to IPv6. The address size jumps dramatically from 32 bits to 128 bits, providing a vastly increased address space that allows improved route aggregation across the Internet and offers large subnet allocations of a minimum of 264 host addresses to end-users. Migration to IPv6 is in progress but is expected to take considerable time.
Methods to mitigate the IPv4 address exhaustion are:
See main article: Network address translation.
One method to increase both address utilization and security is to use network address translation (NAT).With NAT, assigning one address to a public machine as an internet gateway and using a private network for an organization's computers allows for considerable address savings.This also increases security by making the computers on a private network not directly accessible from the public network.
See main article: Virtual private network.
Since private address ranges are deliberately ignored by all public routers, it is not normally possible to connect two private networks (e.g., two branch offices) via the public Internet. Virtual private networks (VPNs) solve this problem.
VPNs work by inserting an IP packet (encapsulated packet) directly into the data field of another IP packet (encapsulating packet) and using a publicly routable address in the encapsulating packet. Once the VPN packet is routed across the public network and reaches the endpoint, the encapsulated packet is extracted and then transmitted on the private network just as if the two private networks were directly connected.
Optionally, the encapsulated packet can be encrypted to secure the data while it travels over the public network (see VPN article for more details).
An IP packet consists of a header section and a data section.
The header consists of 13 fields, of which only 12 are required. The 13th field is optional (red background in table) and aptly named: options. The fields in the header are packed with the most significant byte first (big endian), and for the diagram and discussion, the most significant bits are considered to come first. The most significant bit is numbered 0, so the version field is actually found in the four most significant bits of the first byte, for example.
|0||Version||Header length||Type of Service|
(now DiffServ and ECN)
|64||Time to Live||Protocol||Header Checksum|
This field is now used for DiffServ and ECN. The original intention was for a sending host to specify a preference for how the datagram would be handled as it made its way through an internet. For instance, one host could set its IPv4 datagrams' TOS field value to prefer low delay, while another might prefer high reliability. In practice, the TOS field has not been widely implemented. However, a great deal of experimental, research and deployment work has focused on how to make use of these eight bits. These bits have been redefined, most recently through DiffServ working group in the IETF and the Explicit Congestion Notification codepoints (see RFC 3168). New technologies are emerging that require real-time data streaming and therefore will make use of the TOS field. An example is Voice over IP (VoIP) that is used for interactive data voice exchange.
If the DF flag is set and fragmentation is required to route the packet then the packet will be dropped. This can be used when sending packets to a host that does not have sufficient resources to handle fragmentation.
When a packet is fragmented all fragments have the MF flag set except the last fragment, which does not have the MF flag set. The MF flag is also not set on packets that are not fragmented — an unfragmented packet is its own last fragment.
|Copied||1||Set to 1 if the options need to be copied into all fragments of a fragmented packet.|
|Option Class||2||A general options category. 0 is for "control" options, and 2 is for "debugging and measurement". 1, and 3 are reserved.|
|Option Number||5||Specifies an option.|
|Option Length||8||Indicates the size of the entire option (including this field). This field may not exist for simple options.|
|Option Data||Variable||Option-specific data. This field may not exist for simple options.|
The last field is not a part of the header and, consequently, not included in the checksum field.The contents of the data field are specified in the protocol header field and can be any one of the transport layer protocols.
Some of the most commonly used protocols are listed below including their value used in the protocol field:
See List of IP protocol numbers for a complete list.
See main article: IP fragmentation. To make IPv4 more tolerant of different networks the concept of fragmentation was added so that, if necessary, a device could break up the data into smaller pieces.This is necessary when the maximum transmission unit (MTU) is smaller than the packet size.
For example, the maximum size of an IP packet is 65,535 bytes while the typical MTU for Ethernet is 1,500 bytes.Since the IP header consumes 20 bytes (without options) of the 1,500 bytes leaving 1,480 bytes of IP data per Ethernet frame (this leads to an MTU for IP of 1,480 bytes).Therefore, a 65,535-byte data payload (including 20 bytes of header information) would require 45 packets (65535-20)/1480 = 44.27, rounded up to 45.
The reason fragmentation was chosen to occur at the IP layer is that IP is the first layer that connects hosts instead of machines.If fragmentation were performed on higher layers (TCP, UDP, etc.) then this would make fragmentation/reassembly redundantly implemented (once per protocol); if fragmentation were performed on a lower layer (Ethernet, ATM, etc.) then this would require fragmentation/reassembly to be performed on each hop (could be quite costly) and redundantly implemented (once per link layer protocol).Therefore, the IP layer is the most efficient one for fragmentation.
When a device receives an IP packet it examines the destination address and determines the outgoing interface to use.This interface has an associated MTU that dictates the maximum data size for its payload.If the MTU is smaller than the data size then the device must fragment the data.
The device then segments the data into segments where each segment is less-than-or-equal-to the MTU less the IP header size (20 bytes minimum; 60 bytes maximum).Each segment is then put into its own IP packet with the following changes:
For example, for an IP header of length 20 bytes and an Ethernet MTU of 1,500 bytes the fragment offsets would be: 0, (1480/8) = 185, (2960/8) = 370, (4440/8) = 555, (5920/8) = 740, etc.
By some chance if a packet changes link layer protocols or the MTU reduces then these fragments would be fragmented again.
For example, if a 4,500-byte data payload is inserted into an IP packet with no options (thus total length is 4,520 bytes) and is transmitted over a link with an MTU of 2,500 bytes then it will be broken up into two fragments:
|Total length||More fragments (MF)|
Now, let's say the MTU drops to 1,500 bytes. Each fragment will individually be split up into two more fragments each:
|Total length||More fragments (MF)|
Indeed, the amount of data has been preserved — 1480 + 1000 + 1480 + 540 = 4500 — and the last fragment offset plus data — 3960 + 540 = 4500 — is also the total length.
Note that fragments 3 & 4 were derived from the original fragment 2. When a device must fragment the last fragment then it must set the flag for all but the last fragment it creates (fragment 4 in this case). Last fragment would be set to 0 value.
When a receiver detects an IP packet where either of the following is true:
then the receiver knows the packet is a fragment.The receiver then stores the data with the identification field, fragment offset, and the more fragments flag.When the receiver receives a fragment with the more fragments flag set to 0 then it knows the length of the original data payload since the fragment offset plus the data length is equivalent to the original data payload size.
Using the example above, when the receiver receives fragment 4 the fragment offset (495 or 3960 bytes) and the data length (540 bytes) added together yield 4500 — the original data length.
Once it has all the fragments then it can reassemble the data in proper order (by using the fragment offsets) and pass it up the stack for further processing.
The Internet Protocol is the protocol that defines and enables internetworking at the Internet Layer and thus forms the Internet. It uses a logical addressing system. IP addresses are not tied in any permanent manner to hardware identifications and, indeed, a network interface can have multiple IP addresses. Hosts and routers need additional mechanisms to identify the relationship between device interfaces and IP addresses, in order to properly deliver an IP packet to the destination host on a link. The Address Resolution Protocol (ARP) perform this IP address to hardware address (MAC address) translation for IPv4. In addition the reverse correlation is often necessary, for example, when an IP host is booted or connected to a network it needs to determine its IP address, unless an address is preconfigured by an administrator. Protocols for such inverse correlations exist in the Internet Protocol Suite. Currently used methods are Dynamic Host Configuration Protocol (DHCP) and, infrequently, inverse ARP.