Loading content...
Every piece of data traveling across a network carries more than just the message itself. Attached to your payload—whether it's an email, a video frame, or a database query—is a carefully structured collection of control information that tells network devices exactly how to handle, route, verify, and deliver that data.
This control information comes in two forms:
Together, headers and trailers transform raw application data into self-describing network units that can traverse complex, heterogeneous networks and arrive intact at their destination. Without them, network devices would have no idea where data came from, where it's going, whether it's corrupted, or how to process it.
By the end of this page, you will understand the structure and purpose of headers and trailers at each network layer. You'll know what information each field carries, why it's necessary, and how network devices use it to deliver data correctly. This knowledge is essential for network debugging, protocol design, and understanding network performance.
A header is a sequence of bytes prepended to data that contains control information required by a specific protocol layer. Headers answer critical questions:
The Universal Header Structure:
While specific fields vary by protocol, most headers follow a pattern:
Headers are placed at the beginning because network devices often need to make routing or processing decisions before reading the entire payload. A router can forward a packet based on just the first 20 bytes (the IP header) without reading possibly megabytes of following data. This enables efficient hardware processing and reduces latency.
Header Processing Flow:
When a network device receives data, it processes headers in order:
This peel-the-onion approach is fundamental to how network stacks process incoming data.
Fixed vs. Variable Length Headers:
Fixed-length headers enable simpler, faster hardware processing. Variable-length headers provide extensibility for optional features.
A trailer is a sequence of bytes appended to data containing control information that must follow the payload. Trailers are less common than headers but serve important purposes:
Why Some Information Goes at the End:
Error detection requires complete data — Computing a CRC checksum requires processing all preceding bytes. The result naturally comes at the end.
Hardware streaming — When transmitting serially, error-check bits can be computed as data streams through and appended at the end without buffering the entire frame.
Framing purposes — Some protocols use trailers to mark frame boundaries.
Where Trailers Are Used:
Higher layers (TCP, IP, UDP) generally don't use trailers—they place checksums in their headers, computing them before transmission rather than during.
| Aspect | Headers | Trailers |
|---|---|---|
| Position | Before payload (prepended) | After payload (appended) |
| Purpose | Addressing, protocol identification, control | Error detection, frame delimiting |
| When computed | Before transmission | During or after payload transmission |
| Layers used | All layers (L2-L7) | Primarily data link layer (L2) |
| Size | Variable by protocol (8-60+ bytes) | Usually small and fixed (4-8 bytes) |
| Processing | Read first to make routing decisions | Read last to verify integrity |
The Frame Check Sequence (FCS):
The most important trailer in networking is the Ethernet FCS—a 4-byte CRC-32 checksum computed over the entire frame (header + payload). When a frame arrives:
This provides Layer 2 error detection but not correction or recovery—that's left to higher layers (TCP retransmission, etc.).
When the FCS check fails, Ethernet silently drops the frame. There's no Layer 2 notification to the sender. This is why higher-layer protocols (TCP) must implement their own reliability mechanisms. UDP applications that need reliability must implement it themselves.
The Ethernet frame is the most common Layer 2 encapsulation format on local networks. Let's examine every field in detail.
Ethernet II Frame Structure:
The complete frame consists of:
Field-by-Field Analysis:
Preamble (7 bytes) — Not technically part of the frame, but physically transmitted before it. Consists of alternating 1s and 0s (10101010 pattern) to allow the receiver's clock to synchronize with the transmitter.
Start Frame Delimiter (SFD) (1 byte) — Value 10101011. The final two 1-bits signal that the actual frame data begins next. After this byte, real addressing begins.
Destination MAC Address (6 bytes / 48 bits): The physical address of the intended recipient:
Special addresses:
FF:FF:FF:FF:FF:FF — Broadcast (all hosts on local network)01:xx:xx:xx:xx:xx) — MulticastSource MAC Address (6 bytes / 48 bits): The physical address of the sender. Same format as destination. Always unicast (first bit = 0); you can't send from a broadcast address.
EtherType (2 bytes / 16 bits): Identifies the protocol encapsulated in the payload:
0x0800 — IPv40x86DD — IPv60x0806 — ARP (Address Resolution Protocol)0x8100 — VLAN-tagged frame (802.1Q)0x8847 — MPLS (unicast)If value is ≤ 1500, it's an IEEE 802.3 frame using length field instead.
Payload (46-1500 bytes): The encapsulated higher-layer data (typically an IP packet). Minimum 46 bytes; if actual data is less, padding (null bytes) is added. Maximum 1500 bytes—the Ethernet MTU.
Frame Check Sequence (FCS) (4 bytes): CRC-32 polynomial checksum computed over destination MAC, source MAC, EtherType, and payload. Detects bit errors from noise, interference, or faulty hardware.
Preamble (7) + SFD (1) + Header (14) + FCS (4) = 26 bytes of overhead per frame. Plus an inter-frame gap of 12 bytes between frames. For small payloads, this overhead is substantial—sending 46 bytes of data requires 72 bytes on the wire.
The IPv4 header is the workhorse of internet routing. Every packet crossing the internet carries this header (or its IPv6 equivalent). Understanding each field is essential for network professionals.
IPv4 Header Structure (20-60 bytes):
Critical Field Analysis:
Version (4 bits): Value 4 for IPv4. Allows receivers to immediately determine IP version.
Internet Header Length (IHL) (4 bits): Header length in 32-bit words. Minimum 5 (= 20 bytes). Maximum 15 (= 60 bytes). Values > 5 indicate options are present.
DSCP/ECN (8 bits total):
Total Length (16 bits): Entire packet size (header + payload) in bytes. Maximum 65,535 bytes. Actual maximum usually limited by link MTU.
Identification (16 bits): Unique identifier for a datagram. Used to reassemble fragments—all fragments of the same original datagram share this ID.
Flags (3 bits):
Fragment Offset (13 bits): Position of this fragment's data in the original datagram, measured in 8-byte units. First fragment has offset 0.
Time to Live (TTL) (8 bits): Hop counter. Decremented by each router. When it reaches 0, packet is discarded and ICMP "Time Exceeded" is sent. Prevents infinite routing loops. Typical initial values: 64 (Linux), 128 (Windows).
Protocol (8 bits): Identifies encapsulated transport protocol:
Header Checksum (16 bits): One's complement of header bytes only (not payload). Must be recomputed at every hop because TTL changes.
Source/Destination IP Addresses (32 bits each): Logical addresses for routing. Unlike MAC addresses, these don't change as the packet traverses routers (except in NAT scenarios).
IPv6 simplified the header significantly: fixed 40-byte header, no header checksum (relies on lower-layer error detection), no fragmentation fields (fragmentation only at source), no options in base header (extension headers instead). This enables faster hardware processing.
The transport layer provides process-to-process communication. TCP and UDP represent opposing design philosophies: TCP prioritizes reliability while UDP prioritizes simplicity and speed.
TCP Header (20-60 bytes):
TCP's extensive header reflects its sophisticated features: reliable delivery, flow control, congestion control, and ordered streaming.
| Field | Size | Purpose |
|---|---|---|
| Source Port | 16 bits | Sending application's port (ephemeral: 49152-65535) |
| Destination Port | 16 bits | Receiving application's port (well-known: 0-1023) |
| Sequence Number | 32 bits | Byte position of first data byte in this segment |
| Acknowledgment Number | 32 bits | Next expected byte from other side (if ACK flag set) |
| Data Offset | 4 bits | Header length in 32-bit words (min 5 = 20 bytes) |
| Reserved | 3 bits | Must be zero (reserved for future use) |
| Flags (9 bits) | NS, CWR, ECE, URG, ACK, PSH, RST, SYN, FIN | Control flags for connection and data flow |
| Window Size | 16 bits | Receive window in bytes (flow control) |
| Checksum | 16 bits | Error detection over header, payload, and pseudo-header |
| Urgent Pointer | 16 bits | Offset to end of urgent data (if URG set) |
| Options | 0-40 bytes | MSS, window scaling, SACK, timestamps, etc. |
TCP Flags Explained:
Common Flag Combinations:
SYN — First packet of three-way handshakeSYN, ACK — Second packet of handshakeACK — Third packet of handshake, and most data packetsFIN, ACK — Connection terminationRST — Immediate connection abortUDP Header (8 bytes):
UDP's minimal header reflects its philosophy: fast, simple, no guarantees.
| Field | Size | Purpose |
|---|---|---|
| Source Port | 16 bits | Sending application's port |
| Destination Port | 16 bits | Receiving application's port |
| Length | 16 bits | Header + payload length in bytes (min 8) |
| Checksum | 16 bits | Error detection (optional in IPv4, mandatory in IPv6) |
Both TCP and UDP checksums are computed over a 'pseudo-header' that includes IP source and destination addresses—even though these are from the IP layer. This cross-layer dependency catches errors where correct transport segments are delivered to the wrong host due to IP header corruption.
Understanding how network devices parse headers is crucial for performance optimization and debugging. Let's examine the processing mechanics.
Sequential Parsing:
Headers are designed for sequential processing:
This enables fast hardware processing without complex parsing logic.
The Type-Length-Value (TLV) Pattern:
Many protocols use the TLV pattern for optional fields:
Examples: IPv6 extension headers, TCP options, DHCP options.
Hardware vs. Software Processing:
| Aspect | Hardware (NIC/Switch) | Software (CPU) |
|---|---|---|
| Speed | Line rate (Gbps+) | Slower, CPU-limited |
| Flexibility | Fixed protocols only | Any protocol |
| Layers processed | L2-L4 (fixed offsets) | L2-L7 (full parsing) |
| Use case | Forwarding, checksums, segmentation | Deep inspection, firewalls, proxies |
| Examples | Switch ASICs, NIC offload | Linux netfilter, application proxies |
Header Offloading:
Modern NICs perform significant header processing in hardware:
Parsing Efficiency:
Network stacks optimize header parsing through:
Header Validation:
Strict validation catches errors early:
Invalid packets are dropped immediately, preventing wasted processing.
Tools like tcpdump use BPF (Berkeley Packet Filter) to filter packets in kernel space before copying to userspace. The BPF filter examines headers to match only interesting packets—avoiding the enormous overhead of copying all traffic to applications.
Headers present both security risks and security opportunities. Understanding header security is essential for network defense.
Header Spoofing Attacks:
Headers can be forged or manipulated:
Defensive Header Inspection:
| Mechanism | Headers Examined | Purpose |
|---|---|---|
| Ingress filtering (BCP38) | IP source address | Drop packets with spoofed source IPs |
| Firewall rules | IP addresses, ports, flags | Allow/deny based on packet characteristics |
| Deep packet inspection | All headers + payload | Detect application-layer threats |
| Rate limiting | Source IP/port | Prevent DoS attacks |
| Port security | Source MAC address | Limit allowed devices on switch port |
| DHCP snooping | DHCP headers, MAC, port | Prevent rogue DHCP servers |
Header Encryption and Authentication:
The Privacy Dilemma:
Headers reveal metadata even when payload is encrypted:
This is why advanced privacy techniques (Tor, VPNs, traffic padding) exist—to obscure header metadata, not just payload content.
Malformed Header Attacks:
Sending deliberately malformed headers can:
A fundamental security principle: any header field can be forged. Source IP addresses may be spoofed. Port numbers may be misleading. TTL values may be manipulated. Always validate what you can, and never trust headers for security-critical decisions without additional verification.
Headers and trailers are the control information that makes networked communication possible. Let's consolidate the key points:
What's Next:
Now that you understand the specific information in headers and trailers, the next page examines Protocol Data Units (PDUs)—the formal names for encapsulated data at each layer (segments, packets, frames) and how understanding PDUs provides a unified vocabulary for discussing network communication.
You now understand headers and trailers—the control information that wraps network data. Headers provide addressing, protocol identification, and control flags that enable routing and processing. Trailers provide integrity verification. Together, they transform raw data into self-describing network units that traverse the internet reliably.