IPv4 Datagram Format
IPv4 Datagram Format
At the network layer, the basic unit of data used by IPv4 is called an IP datagram. An IPv4 datagram has two main parts:
- Header – contains control and delivery information.
- Payload (Data) – contains the actual data received from an upper-layer protocol such as TCP or UDP.
1. IPv4 Datagram Structure
The IPv4 datagram has the following important fields:
| Field | Size | Purpose |
|---|---|---|
| Version (VER) | 4 bits | Identifies the IP version. For IPv4, the value is 4. |
| Header Length (HLEN) | 4 bits | Specifies the size of the IP header in 4-byte words. Header size is 20–60 bytes. |
| Service Type | 8 bits | Indicates how the datagram should be handled; associated with differentiated services. |
| Total Length | 16 bits | Specifies the total size of the datagram, including header and payload. Maximum is 65,535 bytes. |
| Identification | 16 bits | Used in the fragmentation and reassembly of datagrams. |
| Flags | 3 bits | Provides control information related to fragmentation. |
| Fragmentation Offset | 13 bits | Indicates the position of a fragment within the original datagram. |
| TTL (Time to Live) | 8 bits | Limits the number of routers (hops) through which a datagram can travel. |
| Protocol | 8 bits | Identifies the upper-layer protocol carrying the payload, such as TCP or UDP. |
| Header Checksum | 16 bits | Detects errors in the IPv4 header. |
| Source IP Address | 32 bits | IP address of the sender. |
| Destination IP Address | 32 bits | IP address of the receiver. |
| Options + Padding | 0–40 bytes | Optional information used for purposes such as network testing and debugging. |
| Payload | Variable | Actual data carried by the IP datagram. |
2. Important Fields to Understand
Version
For an IPv4 datagram:
Version = 4
This tells the receiving device that the datagram follows the IPv4 format.
Header Length
The IPv4 header can vary from 20 to 60 bytes.
The HLEN field stores the length in 4-byte words.
For example:
- HLEN = 5 → 5 × 4 = 20 bytes
- HLEN = 10 → 10 × 4 = 40 bytes
- HLEN = 15 → 15 × 4 = 60 bytes
Total Length
It represents:
Total Length = Header + Payload
Since the field is 16 bits, the maximum datagram size is:
65,535 bytes
3. Fragmentation Fields
The Identification, Flags, and Fragmentation Offset fields work together when a datagram is too large for the underlying network.
For example, if a large IP datagram must be divided into smaller pieces, these fields help the destination identify, arrange, and reassemble the fragments.
4. TTL — Time to Live
TTL prevents an IP datagram from circulating indefinitely due to routing problems.
Suppose:
TTL = 5
Each router that processes the datagram decreases TTL by 1:
5 → 4 → 3 → 2 → 1 → 0
When the value becomes zero, the router discards the datagram.
So, TTL effectively limits the maximum number of hops a datagram can make.
5. Protocol Field
The Protocol field tells the destination IP layer which protocol should receive the payload.
Some important values are:
| Protocol | Protocol Number |
|---|---|
| ICMP | 1 |
| TCP | 6 |
| UDP | 17 |
| IGMP | 2 |
| OSPF | 89 |
For example:
Application ↓ TCP ↓ IPv4 ↓ Network
If the IPv4 Protocol field contains 6, the payload is delivered to TCP at the destination.
Thus, the Protocol field performs multiplexing at the source and demultiplexing at the destination.
6. Header Checksum
The checksum is used to detect errors in the IPv4 header.
An important point for students:
IPv4 header checksum checks only the IP header, not the payload.
TCP or UDP is responsible for checking the integrity of its own data.
Also, because some header fields such as TTL can change as the datagram passes through routers, the header checksum is recalculated at each router.
7. Source and Destination IP Addresses
These are both 32-bit fields.
- Source IP address → identifies where the datagram came from.
- Destination IP address → identifies where the datagram should go.
The destination address is particularly important for routing and forwarding.
8. Payload
The payload is the actual information being carried by the IP datagram.
For example:
IPv4 Datagram ┌──────────────────────────────┐ │ IP Header │ │ Address, TTL, Protocol, ... │ ├──────────────────────────────┤ │ Payload │ │ TCP segment │ │ or │ │ UDP datagram │ └──────────────────────────────┘
The payload may contain a TCP segment, UDP datagram, ICMP message, or information from another protocol that uses IP.
Summary
For undergraduate students, focus first on these 8 important concepts:
Version → Header Length → Total Length → Fragmentation → TTL → Protocol → IP Addresses → Payload
An IPv4 datagram consists of a header containing information needed for routing, delivery, fragmentation and control, followed by a payload containing the actual data to be delivered.
Comments
Post a Comment