51  Frame Delimiters and Boundaries

51.1 Learning Objectives

By the end of this chapter, you will be able to:

  • Explain framing techniques: Describe how receivers know where packets begin and end
  • Implement byte stuffing: Handle delimiter conflicts in payload data
  • Calculate fragmentation: Determine how large payloads get split across MTU boundaries
  • Choose framing methods: Select appropriate techniques for different protocol requirements

Prerequisites (Read These First): - Packet Anatomy - Headers, payloads, and trailers fundamentals

Companion Chapters (Packet Structure Series): - Packet Structure Overview - Index of all packet structure topics - Error Detection - Checksums, CRC, and data integrity - Protocol Overhead - Header comparison and encapsulation

Networking Foundations: - Networking Fundamentals - Network layers and packet flow - Layered Models - OSI and TCP/IP encapsulation - 6LoWPAN - IPv6 header compression for constrained networks


51.2 Frame Delimiters and Boundaries

Time: ~10 min | Difficulty: Intermediate | Unit: P02.C02.U02

How does a receiver know where one packet ends and another begins?

Networks use several techniques:

51.2.1 Length Field in Header

The header specifies payload size:

Header: [... Length=100 ...] | Payload: [100 bytes] | Trailer: [CRC]
  • Receiver reads header, extracts length field
  • Reads exactly that many payload bytes
  • Used by: IP, TCP, UDP, MQTT

51.2.2 Special Start/End Markers

Unique byte sequences mark boundaries:

[0x7E] Header | Payload | Trailer [0x7E]
  • Start delimiter: Signals new packet
  • End delimiter: Signals completion
  • Used by: Ethernet (preamble), HDLC, PPP

51.2.3 Byte Stuffing / Escaping

What if payload contains the delimiter byte? - Solution: Escape it with a special character - Example: If delimiter is 0x7E, replace payload 0x7E with 0x7D 0x5E - Receiver reverses the escaping

Enhanced Byte Stuffing Example:

Suppose you want to send payload [0x10, 0x7E, 0x20] where 0x7E is the frame delimiter:

Original:  [0x7E] [0x10, 0x7E, 0x20] [0x7E]
           ^^^^   ^^^^^^^^^^^^^^^^^ ^^^^
           Start    Payload        End

Problem: Payload contains 0x7E!

Escaped:   [0x7E] [0x10, 0x7D, 0x5E, 0x20] [0x7E]
                        ^^^^^^^^^
                        Escape sequence

Receiver: Sees 0x7D -> reads next byte -> converts 0x5E back to 0x7E

51.3 MTU and Fragmentation

Maximum Transmission Unit (MTU) is the largest packet size a network can handle:

Network Type MTU Size Notes
Ethernet 1500 bytes Standard MTU for most wired networks
Wi-Fi 2304 bytes Theoretical max, usually 1500 in practice
LoRaWAN 51-242 bytes Varies by data rate (DR0-DR5)
BLE 27 bytes Without fragmentation
Zigbee 127 bytes IEEE 802.15.4 frame size

If your payload exceeds MTU, the network layer fragments it into multiple packets, each with its own header/trailer overhead.


Explore how large packets get fragmented when they exceed the Maximum Transmission Unit (MTU). Adjust the payload and MTU sizes to see fragmentation in action.

51.3.1 Fragmentation Results

51.3.2 Visual Fragmentation Display

51.3.3 Fragment Details Table

51.3.4 Reassembly at Destination

51.3.5 6LoWPAN Fragmentation Header Structure

51.3.6 Efficiency Analysis

Tips for optimal fragmentation: - Choose MTU close to your typical payload size to minimize fragments - 6LoWPAN uses 8-byte offset units, so align payloads accordingly - Consider payload batching to amortize fragment header overhead - Monitor reassembly timeout in constrained networks (fragments may arrive out of order)


51.4 Framing Techniques Comparison

Three vertical flowcharts comparing packet framing methods. Length Field Method: Header with Length=100 (navy) flows to Payload 100 bytes (teal) flows to Trailer CRC (orange), used by IP/TCP/UDP/MQTT/CoAP. Delimiter Method: Start delimiter 0x7E (orange) flows through Header (navy), Payload (teal), Trailer (orange), to End delimiter 0x7E (orange), used by Ethernet/HDLC/PPP. Byte Stuffing Method: Start 0x7E (orange) flows through Data 0x10 (teal), Escape sequence 0x7D 0x5E (orange), Data 0x20 (teal), to End 0x7E (orange), used by HDLC/PPP/SLIP. Dotted lines connect each method to its protocol implementations.

Three vertical flowcharts comparing packet framing methods. Length Field Method: Header with Length=100 (navy) flows to Payload 100 bytes (teal) flows to Trailer CRC (orange), used by IP/TCP/UDP/MQTT/CoAP. Delimiter Method: Start delimiter 0x7E (orange) flows through Header (navy), Payload (teal), Trailer (orange), to End delimiter 0x7E (orange), used by Ethernet/HDLC/PPP. Byte Stuffing Method: Start 0x7E (orange) flows through Data 0x10 (teal), Escape sequence 0x7D 0x5E (orange), Data 0x20 (teal), to End 0x7E (orange), used by HDLC/PPP/SLIP. Dotted lines connect each method to its protocol implementations.
Figure 51.1: Comparison of three framing techniques: length field (header specifies payload size), delimiter method (special markers indicate boundaries), and byte stuffing (escape sequences handle delimiter conflicts in payload). Each method has trade-offs between simplicity, reliability, and overhead.

%%{init: {'theme': 'base', 'themeVariables': {'primaryColor': '#2C3E50', 'primaryTextColor': '#fff', 'primaryBorderColor': '#16A085', 'lineColor': '#16A085', 'secondaryColor': '#E67E22', 'tertiaryColor': '#7F8C8D'}}}%%
flowchart TD
    START([Which framing<br/>technique?]) --> Q1{Known payload<br/>length?}

    Q1 -->|"Yes, always"| LEN["Length Field<br/>โ”โ”โ”โ”โ”โ”โ”<br/>Header tells receiver<br/>exactly how many<br/>bytes to read"]

    Q1 -->|"Variable/Unknown"| Q2{Can control<br/>payload content?}

    Q2 -->|"Yes"| DELIM["Delimiters<br/>โ”โ”โ”โ”โ”โ”โ”<br/>Use unique marker<br/>bytes 0x7E at<br/>start and end"]

    Q2 -->|"No - arbitrary data"| STUFF["Byte Stuffing<br/>โ”โ”โ”โ”โ”โ”โ”<br/>Escape delimiter<br/>bytes that appear<br/>in payload"]

    LEN --> PROS1["Pros: Fast, no scanning<br/>Cons: Must know length first"]
    DELIM --> PROS2["Pros: Simple detection<br/>Cons: Delimiter conflicts"]
    STUFF --> PROS3["Pros: Handles any data<br/>Cons: Variable overhead"]

    PROS1 --> EX1["Use: IP, TCP, UDP<br/>MQTT, CoAP"]
    PROS2 --> EX2["Use: Ethernet preamble<br/>HDLC, Serial"]
    PROS3 --> EX3["Use: PPP, SLIP<br/>Binary protocols"]

    style START fill:#2C3E50,stroke:#16A085,stroke-width:3px,color:#fff
    style Q1 fill:#16A085,stroke:#2C3E50,stroke-width:2px,color:#fff
    style Q2 fill:#16A085,stroke:#2C3E50,stroke-width:2px,color:#fff
    style LEN fill:#2C3E50,stroke:#16A085,stroke-width:2px,color:#fff
    style DELIM fill:#2C3E50,stroke:#16A085,stroke-width:2px,color:#fff
    style STUFF fill:#2C3E50,stroke:#16A085,stroke-width:2px,color:#fff
    style PROS1 fill:#E67E22,stroke:#2C3E50,stroke-width:1px,color:#fff
    style PROS2 fill:#E67E22,stroke:#2C3E50,stroke-width:1px,color:#fff
    style PROS3 fill:#E67E22,stroke:#2C3E50,stroke-width:1px,color:#fff
    style EX1 fill:#ecf0f1,stroke:#2C3E50,stroke-width:1px,color:#000
    style EX2 fill:#ecf0f1,stroke:#2C3E50,stroke-width:1px,color:#000
    style EX3 fill:#ecf0f1,stroke:#2C3E50,stroke-width:1px,color:#000

Figure 51.2: Alternative view: Decision Tree for Framing Selection - Instead of showing how each technique works, this decision tree helps engineers choose the right framing method. Start with your constraints: If payload length is always known, use length fields. If you control the data and can avoid certain bytes, use delimiters. If arbitrary binary data must pass through, use byte stuffing. Each path shows trade-offs (pros/cons) and real protocol examples. {fig-alt=โ€œDecision tree flowchart for choosing packet framing technique. Starting question (navy): Which framing technique? First decision (teal): Known payload length? If yes, go to Length Field method (navy box explaining header tells receiver exact byte count). If variable/unknown, second decision (teal): Can control payload content? If yes, go to Delimiters method (navy box explaining unique marker bytes at start/end). If no (arbitrary data), go to Byte Stuffing method (navy box explaining escape delimiter bytes). Each method connects to Pros/Cons box (orange) then to protocol examples (gray). Length Field: fast but must know length first, used by IP/TCP/UDP/MQTT/CoAP. Delimiters: simple detection but delimiter conflicts, used by Ethernet/HDLC/Serial. Byte Stuffing: handles any data but variable overhead, used by PPP/SLIP/binary protocols.โ€}

WarningCommon Misconception: โ€œSmaller Packets Are Always Betterโ€

The Myth: โ€œTo save bandwidth, I should make my packets as small as possible by minimizing headers and sending frequent tiny updates.โ€

Why This Is Wrong:

While minimizing packet size seems logical, header overhead doesnโ€™t scale linearly. Consider this example:

Scenario 1: Many Small Packets - Send 100 temperature readings (2 bytes each) as 100 separate packets - Each packet needs 13-byte LoRaWAN header + 4-byte MIC = 17 bytes overhead - Total: (2 + 17) x 100 = 1,900 bytes - Overhead: 1,700 bytes (89.5%)

Scenario 2: One Batched Packet - Send all 100 readings in one packet - Packet: 13-byte header + 200-byte payload + 4-byte MIC = 217 bytes - Overhead: 17 bytes (7.8%) - Savings: 88% less bandwidth!

Additional Hidden Costs of Small Packets: 1. Radio wake-up energy: Each transmission requires powering up the radio (10-100 mW for 1-5 seconds) 2. Protocol overhead: Channel access, preamble, and synchronization for each packet 3. Gateway load: More packets = more processing and database writes 4. Collision risk: More transmissions = higher chance of interfering with other devices

The Right Approach: - Batch data when real-time updates arenโ€™t critical - Balance packet size with latency requirements - Consider MTU limits: Donโ€™t exceed Maximum Transmission Unit (LoRaWAN DR0 = 51 bytes) - Use compression: CBOR or Protocol Buffers can reduce payload size while batching multiple readings

Real-World Impact: A smart building with 500 temperature sensors sending every 10 minutes: - Small packets (2 bytes each): 1.9 GB/year, battery life 1 year - Batched packets (20 readings): 0.23 GB/year, battery life 5+ years - Bandwidth savings: 88%, Cost savings: $167/year at $0.10/MB

The Takeaway: Headers are overhead you pay per packet, not per byte. Batch your data intelligently to minimize both bandwidth costs and energy consumption.


51.5 Knowledge Check: Framing

Knowledge Check: Byte Stuffing Quick Check

Concept: Understanding byte stuffing for delimiter handling.

A stream of bytes arrives: 0x7E 0x45 0x7D 0x5E 0x7E. Using HDLC-style byte stuffing where 0x7E is the delimiter and 0x7D is the escape character, what is the actual payload?

A is correct. First 0x7E = start delimiter. 0x45 = data. 0x7D 0x5E = escaped 0x7E (0x7E XOR 0x20 = 0x5E). Last 0x7E = end delimiter. Byte stuffing allows delimiter bytes to appear in data without breaking frame boundaries.


51.6 Summary

Frame delimiters and boundaries enable reliable packet detection:

  • Length Fields: Header specifies payload size - used by IP, TCP, UDP, MQTT
  • Delimiters: Special marker bytes signal start/end - used by Ethernet, HDLC, PPP
  • Byte Stuffing: Escape sequences handle delimiter conflicts in payload data
  • MTU Limits: Networks fragment packets that exceed Maximum Transmission Unit
  • Fragmentation Overhead: Each fragment adds header bytes, reducing efficiency

Key Takeaways: - Choose framing method based on whether payload length is known in advance - Byte stuffing adds variable overhead but handles arbitrary binary data - Fragmentation multiplies header overhead - batch data when possible - 6LoWPAN fragmentation is designed for constrained IEEE 802.15.4 networks


51.7 Whatโ€™s Next

Continue exploring packet structure with these related chapters:

Continue to Error Detection ->