Sub topic 4
Segment, packet, frame: naming the pieces
This chapter assumes you know what a header and a payload are, and that encapsulation wraps data in one header per layer. It also assumes you can read a byte count and a hexadecimal value. The chapter covers the names for the unit of data at each layer, the sizes involved, and the places where everyday usage ignores those names.
Why the names matter
A protocol data unit (PDU) is the unit of data that one protocol layer hands to the layer below. Each layer wraps the PDU from the layer above with its own header, so the same bytes carry a different name as they move down the stack.
The names tell you which layer you are discussing. "The segment was lost" and "the frame was corrupted" point to different layers, different headers and different tools. A frame with a bad checksum is dropped by the network card. A segment that never arrives is retransmitted by TCP on the sending host.
The names, layer by layer
| TCP/IP layer | OSI layer | PDU name | Header added | Identifies |
|---|---|---|---|---|
| Application | 5 to 7 | Data or message | Protocol-specific (for example HTTP) | A request or a response |
| Transport | 4 | Segment (TCP) or datagram (UDP) | TCP or UDP header | Source and destination port |
| Internet | 3 | Packet | IP header | Source and destination IP address |
| Link | 2 | Frame | Ethernet header and trailer | Source and destination MAC address |
| Physical | 1 | Bits | None | Signals on the medium |
Three details in the table are easy to miss:
- TCP and UDP have different PDU names. A TCP unit is a segment. A UDP unit is a datagram.
- The link layer adds a trailer as well as a header. Ethernet appends a 4-byte frame check sequence (FCS), which detects corruption.
- The physical layer has no header. It turns the frame into signals, so its "PDU" is a stream of bits.
One request, four sizes
The diagram shows an HTTP request moving down the stack. Each box contains the box above it.
The following script counts the bytes at each layer for the request used in the chapter's earlier example. The header sizes assume no TCP options, no IPv4 options and no VLAN tag.
http = b"GET / HTTP/1.1\r\nHost: example.com\r\n\r\n"
TCP_HEADER = 20 # bytes, no options
IPV4_HEADER = 20 # bytes, no options
ETH_HEADER = 14 # bytes, no VLAN tag
ETH_FCS = 4 # appended by the network card
ETH_MIN_PAYLOAD = 46 # shorter payloads are padded with zeros
data_len = len(http)
segment_len = TCP_HEADER + data_len
packet_len = IPV4_HEADER + segment_len
frame_len = ETH_HEADER + max(packet_len, ETH_MIN_PAYLOAD)
on_wire_len = frame_len + ETH_FCS
rows = [
("Application data", data_len),
("TCP segment", segment_len),
("IPv4 packet", packet_len),
("Ethernet frame", frame_len),
("Frame with FCS", on_wire_len),
]
for name, size in rows:
print(f"{name:<18}{size:>4} bytes")The output is 37, 57, 77, 91 and 95 bytes. The 58 bytes of headers are about 61 percent of the 95 bytes on the wire. With a small request the headers outweigh the data, which is why small messages use a link inefficiently.
Padding and minimum frame size
Ethernet requires a frame of at least 64 bytes including the FCS. That means at least 46 bytes of payload. A TCP acknowledgment with no data is a 40-byte IP packet, so the sender pads it with 6 zero bytes. The IP header's total length field still says 40, so the receiver ignores the padding when it decapsulates. This is why the code above uses max(packet_len, ETH_MIN_PAYLOAD).
What counts toward each size
Size limits apply to specific units, and mixing them up causes off-by-N errors.
- MTU (maximum transmission unit) is the largest payload a link layer frame can carry. For standard Ethernet it is 1500 bytes. The 14-byte Ethernet header and the FCS are not counted, so the largest untagged frame is 1518 bytes.
- IP packet length includes the IP header. A 1500-byte MTU therefore allows a 1500-byte packet.
- MSS (maximum segment size) is the largest amount of TCP data in a segment, not counting the TCP header. With a 1500-byte MTU and 20-byte IPv4 and TCP headers, the MSS is 1500 − 20 − 20 = 1460 bytes.
- A VLAN tag adds 4 bytes to the Ethernet header. The MTU stays at 1500, so the largest tagged frame is 1522 bytes.
The preamble (7 bytes) and start-of-frame delimiter (1 byte) precede every Ethernet frame on the wire. Capture tools never show them, and most sizing discussions leave them out.
Where the names break down
Real usage is looser than the table.
"Packet" is used for everything
Engineers call almost any unit a packet, and capture tools follow that habit. A "packet capture" file contains frames. Strictly, a packet is the IP-layer unit. When a precise answer matters, state the layer, as in "the TCP segment" or "the Ethernet frame".
RFCs say "datagram" for IP
RFC 791 defines the IPv4 unit as an internet datagram. Many texts use "datagram" for the IP layer and "packet" for the same thing. Treat the two as synonyms at layer 3. At layer 4, "datagram" means UDP only.
Wireshark's "frame"
Wireshark numbers every captured item as "Frame N" and then lists the Ethernet, IP and TCP layers under it. The "frame" line there describes the capture record, not only the Ethernet frame. Its length is what the capture library delivered, which usually lacks the FCS.
Fragments and TCP streams
TCP presents a byte stream, so the application never sees segment boundaries. One send call can become several segments, and several calls can share one. UDP preserves message boundaries, so one sendto produces one datagram. When an IP packet is too large for a link, the sender or a router splits it into fragments. Each fragment is itself an IP packet with its own header.
Checking the names in a capture
You can see all four names in one capture. This command prints the link-layer header (-e), the IP header (-v) and numeric values (-nn) for five packets.
sudo tcpdump -i eth0 -e -nn -v -c 5 tcp port 80In the output, the first line gives the Ethernet source and destination MAC addresses, the EtherType and a length value. That length is the whole frame as captured. The following line reports length again, but for the IP total length, and that is the packet. The TCP flags and length at the end of the line describe the segment's data. Reading those three lengths against the frame, packet and segment definitions is a quick way to check your understanding. A frame's length minus 14 should equal the packet's length. A packet's length minus the IP header and TCP header should equal the TCP data length.
Common mistakes
- Calling a UDP unit a segment. The unit is a datagram. Segment is a TCP term.
- Counting the Ethernet header in the MTU. The MTU is the payload limit. The header sits outside it.
- Computing MSS as 1500. The MSS is 1500 minus both the IP and TCP headers, so it is 1460 for IPv4 without options.
- Expecting the capture length to include the FCS. Most captures omit it, because the network card strips it or checks it before the host sees the frame.
- Assuming one
sendis one segment. TCP may split or merge data, so boundaries are not preserved.
Exercise
An application sends 1000 bytes of data over TCP, with no TCP or IPv4 options and no VLAN tag. What are the sizes of the segment, the packet, and the Ethernet frame without the FCS? Does the data fit in one frame on a 1500-byte MTU link?
Show answer
The segment is 1020 bytes (20-byte TCP header + 1000). The packet is 1040 bytes (20-byte IPv4 header + 1020). The frame is 1054 bytes (14-byte Ethernet header + 1040), or 1058 bytes with the FCS. The 1040-byte packet is below the 1500-byte MTU, so the data fits in one frame.
Exercise
A capture shows an Ethernet frame of 1514 bytes without the FCS, carrying an IPv4 packet with no options and a TCP segment whose header is 32 bytes because of options. How many bytes of TCP data does it carry, and is the frame at the limit of a 1500-byte MTU?
Show answer
The IP packet is 1514 − 14 = 1500 bytes, which equals the MTU, so the frame is at the limit. The TCP segment is 1500 − 20 = 1480 bytes. The TCP data is 1480 − 32 = 1448 bytes.
Exercise
Which of these is the correct PDU name: (a) a UDP unit at the transport layer, (b) the unit at the network layer, (c) the unit at the link layer?
Show answer
(a) datagram, (b) packet (RFC 791 also calls the IPv4 unit a datagram), (c) frame.