A widely used Network Layer Protocolb.

It precedes IPv6, which is also widely used today.

Datagram Format

The key fields in the IPv4 Datagram are:

  • Version: 4 bits specifying the IP protocol version. Routers use this to interpret the rest of the Datagram, since different versions have different datagram formats.
  • Header length: 4 bits determining the length of the header. Used to identify when the payload begins, since IPv4 datagram headers can be of variable length due to the variable number of options.
  • Type of service: 8 bits to distinguish different types of IP datagrams, which can be useful for giving special privilege to the forwarding of real-time datagrams (like IP-telephony) over non-real-time datagrams (like FTP).
  • Datagram length: 16 bits to state the total length of the Datagram (header plus data) measured in bytes.
  • Identifier, flags, fragmentation offset: Used for IP Fragmentation.
  • Time-to-live (TTL): 16 bits used to determine how many times the datagram should be processed by a Router before being dropped. It is used to ensure that Datagrams do not circulate forever. The number is decremented every time the datagram is processed and when it reaches 0 the datagram is dropped.
  • Upper-layer protocol: 16 bits that states the specific Transport Layer protocol to which the payload of the datagram should be passed. The value 6 means TCP and 17 means UDP.
  • Header checksum: 16 bits used to aid Routers in detecting bit errors in received Datagrams by computing a Checksum and checking that it is equal to the checksum in this field. Needs to be recomputed and stored at each router since the TTL field and possibly the options field will change.
  • Source IP address and Destination IP address: When a source creates a Datagram it inserts it own IP address in the source IP address field and the address of the final destination in the Destination IP address.
  • Options: Allows for extension of the header.
  • Data: The payload of the Datagram, which often contains a Segment, but can also contain other types of data such as ICMP messages.

Assuming no options an IPv4 Datagram contains a header of size 20 bytes.