Computer Networks · IPv4 Header
IPv4 Header Format: Fields and Sizes
Overview
The IPv4 header is the control structure used by the IP layer (network layer) of the TCP/IP stack; it carries addressing, fragmentation and error-detection information along with the payload.
Its size is variable because of the Options field, so a Header Length field is required to mark where the header ends and the data begins. All field sizes are measured in bits, not bytes.
Key concepts
- IPv4 Header: the header used by the IP layer (network layer) of the TCP/IP stack; it carries control information (addressing, fragmentation, error detection) together with the payload.
- Variable size: the header length is not fixed because the Options field may or may not be present; the Header Length field tells the receiver the actual header length, i.e. where the header ends and the data begins.
- Version: 4 bits; the value 4 means IPv4.
- Header Length (HL): gives the length of the header.
- Type of Service (TOS): 8 bits.
- Total Length: 16 bits.
- Identification: 16 bits; the identification number used for fragmentation and reassembly.
- Reserved bit: 1 bit, always set to 0; it is not used.
- Flags: include DF (Do Not Fragment), 1 bit, meaning the packet must not be fragmented, and MF (More Fragments), 1 bit, meaning more fragments follow.
- Fragment Offset: 13 bits.
How it works
The IPv4 header fields, in order, with their sizes in bits:
- Version — 4 bits (value 4 means IPv4).
- Header Length (HL) — gives the length of the header; needed because the header size is variable.
- Type of Service (TOS) — 8 bits.
- Total Length — 16 bits.
- Identification — 16 bits (identification number used for fragmentation/reassembly).
- Reserved bit — 1 bit, set to 0; unused.
- Flags — DF (Do Not Fragment), 1 bit (packet must not be fragmented); MF (More Fragments), 1 bit (more fragments follow).
- Fragment Offset — 13 bits.
Formulas
- Version = 4 bits
- Header Length = field giving the header size
- Type of Service = 8 bits
- Total Length = 16 bits
- Identification = 16 bits
- Reserved = 1 bit (always 0)
- DF = 1 bit (Do Not Fragment)
- MF = 1 bit (More Fragments)
- Fragment Offset = 13 bits
Revision summary
- All field sizes are in bits, not bytes.
- The header is variable in size because of the Options field; this is why the Header Length field exists.
- The reserved bit is unused and always set to 0.
- DF and MF are single-bit flags; Fragment Offset is 13 bits.
- Exam tip (GATE): for very big data, circuit switching is better; for small data, packet switching is better.
Previous-year exam insights
- The IPv4 header is 20 bytes (5 words) minimum;
with the 4-bit HL field counted in 4-byte words, header length in bytes = HL × 4, and the payload length = Total Length − HL × 4.
Asked inGATE 2013ISRO 2014 - The IPv4 header fields after Fragment Offset are: Time to Live (8 bits), Protocol (8 bits, identifies the upper-layer protocol, e.g. 1 = ICMP, 6 = TCP, 17 = UDP), Header Checksum (16 bits), Source IP address (32 bits), Destination IP address (32 bits), Options (variable), Padding.
Asked inGATE 2004ISRO 2014GATE 2006 - The IPv4 header checksum covers only the header (not the payload) and is recomputed at every router; the Ethernet frame uses a 32-bit CRC trailer, not a checksum field in the header.
Asked inGATE 2006 - The IPv4 header contains no port numbers; ports belong to TCP/UDP headers. Asked inGATE 2004
- For a fragment: first byte of payload = fragment offset × 8;
last byte of payload = fragment offset × 8 + (Total Length − HL × 4) − 1;
MF = 0 with nonzero offset means last fragment.
Asked inGATE 2013ISRO 2014 - The first 4-bit nibble of the datagram is the Version; a value other than 4 (e.g. 6) means the packet is not IPv4 and is rejected/discarded by an IPv4 receiver.
Asked inISRO 2014
IPv4 header field layout
Drawing the diagram…
Shows the IPv4 header fields in order with their sizes in bits, from Version through Fragment Offset.