# IPv4 Header
## What is the IPv4 Header
The IPv4 header is the control information that precedes the data payload in every IPv4 packet. It contains fields that allow routers and destination hosts to properly handle the packet. Understanding the IPv4 header is essential for understanding how IP routing and fragmentation work, and for analyzing network traffic. The minimum IPv4 header size is 20 bytes, and it can be up to 60 bytes if options are included.
## IPv4 Header Fields
The version field is 4 bits wide and contains the value 4 for IPv4 packets. This allows routers to distinguish between IPv4 and IPv6 packets.
The internet header length field is 4 bits wide and specifies the length of the header in 32-bit words. The minimum value is 5, representing 20 bytes.
The differentiated services code point field, formerly called type of service, is 8 bits wide and is used for quality of service purposes to mark packets for different treatment by routers.
The total length field is 16 bits wide and specifies the total length of the packet including header and data, in bytes. The maximum is 65,535 bytes.
The identification field is 16 bits wide and is used to identify the fragments of a single original packet when fragmentation has occurred.
The flags field is 3 bits wide. The don't fragment bit prevents routers from fragmenting the packet. If fragmentation would be required but the don't fragment bit is set, the router drops the packet and sends an ICMP error. The more fragments bit indicates that more fragments of the original packet follow.
The fragment offset field is 13 bits wide and indicates where in the original packet the data in this fragment belongs.
The time to live field is 8 bits wide and is decremented by 1 at each router. When it reaches zero, the packet is discarded. This prevents packets from circulating indefinitely.
The protocol field is 8 bits wide and identifies the transport layer protocol in the data portion. The value 6 indicates TCP, 17 indicates UDP, and 1 indicates ICMP.
The header checksum field is 16 bits wide and provides error detection for the header. It is recalculated at each router because the TTL field changes at each hop.
The source address field is 32 bits wide and contains the IP address of the packet's origin.
The destination address field is 32 bits wide and contains the IP address of the intended recipient.
The options field is variable length and can include additional control information such as record route, timestamp, or security options.Back to Subject