Internet Protocol version 4 is the fourth iteration of the Internet Protocol (IP) and it is the first version of the protocol to be widely deployed. IPv4 is the dominant network layer protocol on the internet and when ignoring its successor — IPv6 — it is the only protocol used on the internet.
It is described in IETF RFC 791 (September 1981) which obsoleted RFC 760 (January 1980). The United States Department of Defense also standardized it as MIL-STD-1777.
IPv4 is a data-oriented protocol to be used on a packet switched internetwork (e.g., Ethernet). It is a best effort protocol in that it doesn't guarantee delivery. It doesn't make any guarantees on the correctness of the data; it may result in duplicated packets and/or packets out-of-order. All of these things are addressed by an upper layer protocol (e.g., TCP, UDP).
The entire purpose of IP is to provide unique global computer addressing to ensure that two computers over the internet can uniquely identify one another.
IPv4 uses 32-bit (4-byte) addresses, which limits the address space to 4,294,967,296 possible unique addresses. However, many are reserved for special purposes such as private networks (~18 million addresses) or multicast addresses (~1 million addresses). This reduces the number of addresses that can be allocated as public Internet addresses and as the number of addresses available is consumed, an IPv4 address shortage appears to be inevitable in the long run.
This limitation has helped stimulate the push towards IPv6, which is currently in the early stages of deployment and is currently the only contender to replace IPv4.
For example, the IPv4 address for www.wikipedia.org is 207.142.131.235 in the dot-decimal notation which comprises four octets in decimal separated by periods. This is the base format used in the conversion in the following table:
| Notation | Value | Conversion from dot-decimal |
|---|---|---|
| Dot-decimal notation | 207.142.131.235 | N/A |
| Dotted Hexadecimal | 0xCF.0x8E.0x83.0xEB | Each octet is individually converted to hex |
| Dotted Octal | 0317.0216.0203.0353 | Each octet is individually converted into octal |
| Hexadecimal | 0xCF8E83EB | Concatenation of the octets from the dotted hexadecimal |
| Decimal | 3482223595 | The hexadecimal form converted to decimal |
| Octal | 031743501753 | The hexadecimal form converted to octal |
All/most of these formats should work in all browsers. Additionally, in dotted format, each octet can be of the different bases. For example, 207.0x8E.0203.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 in both the source and destination fields.
This created an upper limit of 256 networks and led to the creation of classful networks. Under classful networking, 5 classes were created (A, B, C, D, & E) with 3 created (A, B, & C) with different lengths of network number and rest fields to change the number of IPs in each range: few networks with lots of addresses and numerous networks with only a few addresses. Class D was for multicast addresses and class E is reserved.
Around 1993, the classful networks were replaced with a Classless Inter-Domain Routing (CIDR) scheme. CIDR's primary advantage is to allow subdivision of networks to let entities sub-allocate IPs (e.g., an ISP to a customer).
The actual assignment of an address is not arbitrary. The fundamental principle of routing is that address encodes information about a 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 address 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 |
| 14.0.0.0/8 | Public data network | RFC 1700 |
| 39.0.0.0/8 | Reserved | RFC 1797 |
| 127.0.0.0/8 | Localhost | RFC 1700 |
| 128.0.0.0/16 | Reserved | |
| 169.254.0.0/16 | Zeroconf | RFC 3927 |
| 172.16.0.0/12 | Private network | RFC 1918 |
| 191.255.0.0/16 | ||
| 192.0.0.0/24 | ||
| 192.0.2.0/24 | Test network | RFC 3330 |
| 192.88.99.0/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 |
| 223.255.255.0/24 | Reserved | RFC 3330 |
| 224.0.0.0/4 | Multicasts (former Class D network) | RFC 3171 |
| 240.0.0.0/4 | Reserved (former Class E network) | RFC 1700 |
| 255.255.255.255 | Broadcast | |
The following are the three ranges reserved for private networks:
| Name | IP address range | number of IPs | classful description | largest CIDR block |
|---|---|---|---|---|
| 24-bit block | 10.0.0.0 – 10.255.255.255 | 16,777,215 | 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 Bs | 172.16.0.0/12 |
| 16-bit block | 192.168.0.0 – 192.168.255.255 | 65,535 | 256 contiguous class Cs | 192.168.0.0/16 |
In addition to private networking, the IP range 127.0.0.0 – 127.255.255.255 (or 127.0.0.0/8 in CIDR notation) is reserved for localhost communication. Any address within this range should never appear on an actual network and any packet sent to this address does not leave the source computer, and will appear as an incoming packet on that computer (known as Loopback).
The Internet is most publicly known not by IP addresses but by names (e.g., www.wikipedia.org, www.whitehouse.gov, www.freebsd.org, www.mit.edu). The routing of IP packets across the Internet is oblivious to such names. This requires translating (or resolving) names to IP address.
The Domain Name System (DNS) provides such a system to convert names to IP address(es) and IP addresses to names. Much like CIDR addressing, the DNS naming is also hierarchical and allows for subdelegation of name spaces to other DNS servers.
Today, there are several driving forces to the next address allocation solution:
The most visible solution is to migrate to IPv6 since the address size jumps dramatically from 32-bit to 128-bit which would allow about 18 quintillion people their own set of 18 quintillion addresses (3.4e38 total addresses). However, migration has proved to be a challenge in itself, and total Internet adoption of IPv6 is unlikely to occur for many years.
Some things that can be done to mitigate the IPv4 address exhaustion are (not mutually exclusive):
As of 2004, predictions for the exhaustion of the IPv4 address space range from 2016 (for unallocated pool exhaustion) to 2023 (for complete exhaustion of the address space). Historically, though, forward predictions for the date of address exhaustion have been unreliable; predictions from the late 1980s have not been borne out in practice.
One method to increase both address utilization and security is to use network address translation (NAT). By assigning one IP 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 all of the computers on a private network not directly accessible from the public 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 over the public network (see VPN article for more details).
Since IP is an upper layer protocol to the data link layer there arises a problem of when a computer with IP address A wants to communicate with IP address B. In order to send a packet from A to B, A needs to know the hardware address of B. This discovery is done through Address Resolution Protocol (ARP).
Unlike the situation outlined for ARP, the case arises when a computer knows its data link layer address but not its IP address. This is a common scenario in private networks and Digital Subscriber Line (DSL) connections when the IP address of the machines are irrelevant. This is usually the case for work stations but not servers.
RARP is an obsoleted method for answering this question: This is my hardware address, what is my IP address? RARP was replaced by BOOTP which, in turn, was replaced by Dynamic Host Configuration Protocol (DHCP).
In addition to sending the IP address, DHCP can also send the NTP server, DNS servers, and more.
| + | Bits 0 - 3 | 4 - 7 | 8 - 15 | 16 - 18 | 19 - 31 | |||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | Version | Header length | Type of Service (now DiffServ and ECN) | Total Length | ||||||||||||||||||||||||||||
| 32 | Identification | Flags | Fragment Offset | |||||||||||||||||||||||||||||
| 64 | Time to Live | Protocol | Header Checksum | |||||||||||||||||||||||||||||
| 96 | Source Address | |||||||||||||||||||||||||||||||
| 128 | Destination Address | |||||||||||||||||||||||||||||||
| 160 | Options | |||||||||||||||||||||||||||||||
| 160/192+ | Data | |||||||||||||||||||||||||||||||
Some of the most commonly used protocols are listed below including their value used in the protocol field:
See List of IPv4 protocol numbers for a complete list.
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 would require 45 packets (65535/1480 = 44.28).
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 be redundantly implemented (once per protocol); if fragmentation were performed on a lower layer (Ethernet, ATM, etc.) then this would require fragmentation/reassembly be performed on each hop (could be quite costly) and redundantly implemented (once per link layer protocol). So doing fragmentation at the IP layer is the most efficient layer for this to be done.
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, 2960, 4440, 5920, 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) flag set? | Fragment offset | |
|---|---|---|---|---|
| Header | Data | |||
| 1 | 2500 | rowspan="2" align="center" | 0 | |
| 20 | 2480 | |||
| 2 | 2040 | rowspan="2" align="center" | 2480 | |
| 20 | 2020 | |||
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) flag set? | Fragment offset | |
|---|---|---|---|---|
| Header | Data | |||
| 1 | 1500 | rowspan="2" align="center" | 0 | |
| 20 | 1480 | |||
| 2 | 1020 | rowspan="2" align="center" | 1480 | |
| 20 | 1000 | |||
| 3 | 1500 | rowspan="2" align="center" | 2480 | |
| 20 | 1480 | |||
| 4 | 560 | rowspan="2" align="center" | 3960 | |
| 20 | 540 | |||
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 3 in this case).
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 not set 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 (3960) and the data length (540) 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.
Internet protocols | Internet standards | Internet architecture
IPv4 | IPv4 | IPv4 | IPv4 | IPv4 | IPv4 | Internet Protocol Version 4 | IPv4 | IPv4 | IPv4 | Protocolo IP | IPv4 | IPv4 | IPv4 | IPv4 | IPv4