Overview

The Internet Protocol Version 4 (IPv4) Header is a crucial part of Layer 3 in the OSI model, used to route data across different networks, including vast distances over the internet. This header encapsulates a TCP or UDP segment, aiding in the process known as routing.

IPv4 Header Overview


Fields of the IPv4 Header

The IPv4 header contains several fields, each with a specific role in ensuring the proper delivery and processing of packets.

IPv4 Header Fields

Field# of Bits
VERSION4
IHL4
DSCP6
ECN2
TOTAL LENGTH16
IDENTIFICATION16
FLAGS3
FRAGMENT OFFSET13
TIME TO LIVE (TTL)8
PROTOCOL8
HEADER CHECKSUM16
SOURCE ADDRESS32
DESTINATION ADDRESS32
OPTIONS0-320 (Optional)

Version

  • Length: 4 bits
  • Purpose: Identifies the version of IP used (IPv4 or IPv6).
    • IPv4: 0100 in binary (decimal 4)
    • IPv6: 0110 in binary (decimal 6)

Internet Header Length (IHL)

  • Length: 4 bits
  • Purpose: Indicates the total length of the IPv4 header in 4-byte increments.
    • Minimum Value: 5 (5 * 4 bytes = 20 bytes)
    • Maximum Value: 15 (15 * 4 bytes = 60 bytes)

Note: The IPv4 header length can vary between 20 and 60 bytes, depending on the presence of optional fields.


DSCP (Differentiated Services Code Point)

  • Length: 6 bits
  • Purpose: Used for Quality of Service (QoS) to prioritize delay-sensitive data, such as streaming voice or video.

ECN (Explicit Congestion Notification)

  • Length: 2 bits
  • Purpose: Provides end-to-end notification of network congestion without dropping packets.
  • Note: Requires support from both endpoints and the network infrastructure.

Total Length

  • Length: 16 bits
  • Purpose: Indicates the total length of the packet, including the IPv4 header and the encapsulated Layer 4 segment.
  • Range:
    • Minimum: 20 bytes (header only)
    • Maximum: 65,535 bytes (2^16 - 1)

Identification

  • Length: 16 bits
  • Purpose: Used to identify fragments of a packet. All fragments of the same packet have the same identification number.
  • Note: Packets are fragmented if they exceed the Maximum Transmission Unit (MTU), typically 1500 bytes for Ethernet frames.

Flags

  • Length: 3 bits
  • Purpose: Controls and identifies packet fragments.
    • Bit 0: Reserved (always 0)
    • Bit 1 (DF - Don’t Fragment): Indicates if a packet should not be fragmented.
    • Bit 2 (MF - More Fragments): Set to 1 if more fragments follow; 0 for the last fragment or if no fragmentation occurs.

Fragment Offset

  • Length: 13 bits
  • Purpose: Indicates the position of the fragment in the original packet. This helps in reassembling the fragments even if they arrive out of order.

Time to Live (TTL)

  • Length: 8 bits
  • Purpose: Prevents packets from looping indefinitely. Each router that forwards the packet decreases the TTL by 1. If TTL reaches 0, the packet is discarded.
  • Recommended Default: 64

Protocol

  • Length: 8 bits
  • Purpose: Identifies the encapsulated Layer 4 protocol.
    • Examples:
      • 1: ICMP
      • 6: TCP
      • 17: UDP
      • 89: OSPF (Dynamic Routing Protocol)
  • Note: A complete list of protocol numbers can be found on Wikipedia: List of IP Protocol Numbers.

Header Checksum

  • Length: 16 bits
  • Purpose: Ensures the integrity of the IPv4 header by allowing routers to verify its correctness. If the calculated checksum does not match, the packet is dropped.
  • Note: This checksum only verifies the header, not the encapsulated data. Error detection for the data is handled by the encapsulated protocols, such as TCP or UDP.

Source and Destination Addresses

  • Length: 32 bits each
  • Purpose:
    • Source IP: The IPv4 address of the sender.
    • Destination IP: The IPv4 address of the intended recipient.

Options

  • Length: 0-320 bits (variable)
  • Purpose: Optional and rarely used. If the IHL field is greater than 5, options are present.

This polished version of your notes enhances clarity and readability, making it easier to understand and remember the functions of each IPv4 header field.