IP packet/datagram header


20 byte header. (Usually no Options)
Most important fields are Source and Destination IP addresses.
Data field is the payload the packet is carrying, usually a TCP segment or UDP datagram, or an ICMP message, specified by the Protocol field: 1=ICMP, 6=TCP, 17=UDP.
IP packet is another layer of encapsulation. IP's role is to try to get a packet from source host to final destination, travelling thru the networks of the internetwork, hopping from router to router. IP does not guarantee delivery; for that, TCP is used.
16-bit Length field implies <=64KB Data field but usually the TCP/UDP payload has been segmented to fit in an Ethernet frame. Exception: ICMP ping using -l option large "data" will be split into fragments, with common Identification.
TTL field decremented at each hop across internetwork. Packet will be discarded if TTL reaches zero, ensuring endlessly circulating packets are dropped. Basis of traceroute.
This IP packet is carried in the data/payload field of the Ethernet frame.

The Destination IP address is used to guide the packet to the destination. Each router along its path decapsulates the IP packet from its data-link/Layer 2 frame (e.g. Ethernet), decrements the TTL, recalculates the header checksum, determines where the packet should be sent next (i.e. the next hop) by using the router's routing table and re-encapsulates it in the data-link frame appropriate for the next link. The path is not determined at the source nor is the path inside the packet; each router makes the routing decision of where to send the packet to next. Large routers in the internet's backbone are connected to several other routers and so have a choice of where to send an incoming packet. Each router has a routing table that tells it where to send each packet. The routing tables are maintained by the routers passing information to each other using a routing protocol so that the routes in the routing table are the best routes.