Fact-checked by Grok 2 weeks ago

Consistent Overhead Byte Stuffing

Consistent Overhead Byte Stuffing (COBS) is a byte-stuffing algorithm designed to encode sequences of data bytes that may contain reserved values, such as zeros, into a form suitable for unambiguous packet framing over serial links, ensuring reliable transmission without the need for explicit delimiters while guaranteeing a low and predictable overhead of at most one byte per 254 bytes of data. Developed by Stuart Cheshire and Mary Baker, COBS addresses limitations in traditional byte-stuffing methods like PPP, which can suffer from high worst-case overhead (up to 100%) due to pathological data patterns. The algorithm works by dividing the input data into code blocks, where each block begins with a code byte indicating the position of the next zero byte (or the end of the block if no zero is present), followed by the corresponding data bytes; a phantom zero is implicitly appended to the end of the packet to handle the final block. Encoding and decoding are both linear-time operations, implementable with simple assignments, increments, and comparisons, making COBS suitable for resource-constrained environments like embedded systems or hardware. The original COBS adds at most 0.4% overhead and performs well on random data (average 0.23% overhead), while its variant ZPE (Zero Pair Elimination) optimizes for packets containing pairs of zero bytes by encoding them explicitly, achieving a maximum overhead of 0.45% but yielding net size reductions (e.g., -0.26% on real network traces) in scenarios with frequent zero occurrences. Compared to alternatives, COBS provides tighter bounds on overhead—far superior to PPP's variable performance—and has been evaluated on diverse traffic, including three-day network traces (0.57% overhead for COBS) and MPEG video (0.19% overhead), demonstrating its efficiency for applications like networking and serial protocols. Since its introduction in , COBS has become a standard tool in for low-overhead data .

Introduction

Definition and Purpose

Consistent Overhead Byte Stuffing (COBS) is a lossless, variable-length encoding scheme designed for framing packets in data transmission protocols. It transforms arbitrary byte sequences into an encoded form that contains no bytes (0x00), thereby eliminating the need for traditional characters or fixed delimiters within the packet body. This allows packets to be reliably delimited in a continuous byte using a single reserved byte, such as 0x00, placed between consecutive encoded packets. The primary purpose of COBS is to enable unambiguous packet delimitation in asynchronous communications or unstructured byte streams, where traditional methods like SLIP or may introduce unpredictable overhead due to frequent escape sequences for reserved values. By replacing occurrences of zero bytes with position codes that indicate the distance to the next zero (implicitly inserted at block boundaries), COBS ensures that the encoded output never contains a zero byte except as an explicit packet . This approach provides a simple mechanism for framing without requiring bits or complex error-checking schemes, making it suitable for low-level links in or resource-constrained environments. Key benefits of COBS include a maximum overhead of 1 byte per 254 bytes of data (approximately 0.4%), or exactly 1 byte for packets up to 254 bytes, regardless of the data content, which contrasts with variable-overhead schemes that can expand payloads unpredictably. This bounded expansion—typically less than 0.4% for large packets—minimizes bandwidth waste while maintaining computational efficiency, as the algorithm is straightforward to implement in software with low runtime costs. Developed by Stuart Cheshire and Mary Baker, COBS was first introduced in 1997 to address inefficiencies in byte stuffing for serial links.

History and Development

Consistent Overhead Byte Stuffing (COBS) was developed by Stuart Cheshire and Mary Baker at in the late 1990s to address the limitations of existing byte stuffing protocols in resource-constrained environments. Traditional methods such as (SLIP) and (PPP) minimized average overhead but suffered from high worst-case overhead, potentially doubling packet sizes and violating strict transmission limits in devices like ISM-band packet radios regulated by the FCC. (HDLC), while more consistent at 20% overhead, was bit-oriented and less suitable for software implementations in embedded systems. COBS was designed to provide a guaranteed maximum overhead of 1 byte per 254 bytes of data, enabling reliable framing with minimal and predictable expansion for low-power, scenarios. The algorithm was first presented at the ACM SIGCOMM conference in September 1997 in , , where it was highlighted for its efficiency in packet-oriented wireless networks. This was followed by an (IETF) draft in November 1997 proposing COBS as an encapsulation method for PPP, though it did not advance to full RFC status. The formal publication appeared in the IEEE/ACM Transactions on Networking in April 1999, solidifying its theoretical foundations and performance analysis. By the 2010s, COBS saw growing adoption in embedded systems and (IoT) applications for serial framing, particularly in protocols requiring low-overhead, unambiguous packet delineation over noisy channels. A notable integration occurred in 8163 (2017), which specifies COBS encoding for the and fields in Master-Slave/Token-Passing (MS/TP) networks to ensure zero-free byte sequences. In parallel, variants emerged to further optimize performance; for instance, COBS/Reduced (COBS/R), introduced by Craig McQueen around 2010, modifies the encoding to occasionally eliminate the final byte overhead while maintaining computational simplicity, enhancing efficiency in open-source implementations for resource-limited devices. Up to 2025, COBS and its variants continue to be implemented in libraries for microcontrollers and serial links, supporting extensions in automotive networks and protocols, with formal standardization in the IETF via 8163 (2017) for use in MS/TP networks.

Encoding and Decoding

Encoding Process

The encoding process for Consistent Overhead Byte Stuffing (COBS) transforms an input sequence of binary bytes into an output sequence that contains no zero bytes (0x00), allowing zero to serve as a reliable packet delimiter in serial transmissions. This is achieved by logically appending a zero byte to the end of the input (without actually adding it to the output) and then processing the data in a forward pass to replace each zero byte with a code byte that indicates the distance to the next zero (or the logical end). The process guarantees that the output length is at most the input length plus ⌈n/254⌉ bytes, where n is the input length. To perform the encoding, the algorithm uses a single , maintaining a pointer to the position where the next byte will be written and a counter for the number of bytes since the last . Non-zero bytes are copied directly to the output while incrementing the counter. When a zero byte is encountered or the counter reaches 255 (after 254 non-zero bytes), the current counter value is written to the position, and a new position is established after the copied data. At the end of the input, the final block is finished similarly to account for the logical appended zero. If the final block consists of exactly 254 non-zero bytes, a code of 255 is used without implying an additional zero. This ensures no zeros appear in the output and maintains bounded overhead. The following illustrates the core encoding process (adapted from the original implementation for clarity):
function encode(input: byte array of length n) -> byte array:
    output = new byte array of size n + ceil(n / 254)  // Sufficient size
    code_ptr = 0
    dst = 1  // Start after initial code position
    code = 1
    ptr = 0
    while ptr < n:
        if input[ptr] == 0:
            output[code_ptr] = code
            code_ptr = dst
            dst += 1
            code = 1
        else:
            output[dst] = input[ptr]
            dst += 1
            code += 1
            if code == 255:
                output[code_ptr] = 255
                code_ptr = dst
                dst += 1
                code = 1
        ptr += 1
    // Finish the final block
    output[code_ptr] = code
    // Actual output length is dst
    return output[0 .. dst - 1]
Note that this pseudocode uses zero-based indexing and assumes sufficient output buffer; optimizations may adjust for in-place encoding or exact sizing. Edge cases are handled as follows to maintain consistency. For an all-zero packet of length n, each zero triggers an immediate block finish with code 1, followed by the final code 1 for the logical appended zero, resulting in n+1 code bytes each with value 1, producing an output of length n+1 consisting entirely of 0x01 bytes with 1 byte of overhead. Packets ending with a zero are accommodated naturally, as the logical appended zero follows another zero, but the final code placement ensures correct decoding without extra output bytes when paired with conditional insertion. If a sequence of exactly 254 consecutive non-zero bytes ends the packet, the final code is 255, avoiding an unnecessary logical zero implication. In all cases, the algorithm enforces code values from 1 to 255, preventing unbounded expansion. The resulting output is a compact byte stream free of zero bytes, structured as code bytes (1-255) followed by the corresponding non-zero data bytes, where each code byte specifies the length of the following data block (code-1 bytes) and whether a zero follows it (if code < 255). This format allows multiple encoded packets to be concatenated in a stream, delimited only by explicit zero bytes, without ambiguity in parsing individual packets. The process ensures bounded overhead while preserving all original data.

Decoding Process

The decoding process in Consistent Overhead Byte Stuffing (COBS) reverses the encoding algorithm to recover the original binary data from an encoded packet, which consists of code bytes followed by sequences of non-zero data bytes, with no zero bytes present in the encoded form. This process ensures unambiguous reconstruction by using each code byte to indicate the length of the subsequent non-zero byte sequence and the position for reinserting a zero byte where it was removed during encoding. The algorithm is designed for efficiency, operating in a single linear pass over the input data without requiring lookahead or complex buffering. The core decoding algorithm proceeds as follows: initialize input and output pointers at the start of the encoded data; while the input pointer has not reached the end of the packet, read the next byte as the code value c (where $1 \leq c \leq 255); copy the subsequent c - 1 bytes directly from the input to the output; if c < 255 and there are remaining bytes in the input after copying, append a zero byte to the output to restore the original delimiter position; advance the input pointer by c bytes (accounting for the code and the copied data). This loop continues until the entire packet is processed, yielding the original data with all zero bytes reinstated. The approach resembles a simple state machine, transitioning between reading a code byte and copying data bytes, which maintains constant memory usage regardless of packet size. For validation and end-of-packet handling, the decoder implicitly checks the integrity of the input by ensuring each code value does not exceed the remaining packet length; for instance, if c > remaining bytes and c \neq 1, the input is considered invalid, preventing attempts to read beyond the . This basic detection relies on the encoding guarantee that no bytes appear in the encoded packet—if a is encountered during decoding, it signals corruption or a framing , allowing the to discard the packet and resynchronize by seeking the next valid in the stream. No full (CRC) is required, as these structural validations suffice for many low-level framing applications. Pseudocode for the decoding loop, as described in the original specification, illustrates this process clearly:
void DecodeCOBS(const unsigned char *input, unsigned long length, unsigned char *output) {
    const unsigned char *end = input + length;
    unsigned char *out_ptr = output;
    while (input < end) {
        int code = *input++;
        int i;
        for (i = 1; i < code; i++) {
            *out_ptr++ = *input++;
        }
        if (code < 255 && input < end) {  // Avoid inserting zero at exact end if no delimiter follows
            *out_ptr++ = 0;
        }
    }
}
This implementation handles the state transitions efficiently, with the conditional zero insertion preventing extraneous delimiters at the packet's conclusion. Edge cases are managed seamlessly within the algorithm. For all-zero packets, the encoded form consists of repeated code bytes of 1 (indicating no non-zero bytes before each zero), so the decoder repeatedly copies zero data bytes (i.e., none) and inserts a zero after each code less than 255 where remaining input exists, faithfully reconstructing the original sequence without additional overhead or extra bytes. In concatenated streams, where multiple encoded packets are transmitted sequentially (often separated by explicit zero delimiters in the channel), the decoder processes each segment independently upon detecting the delimiter, using the same loop to unstuf each packet while the stream validations ensure no cross-packet corruption propagates. Buffer overflow prevention is inherent, as the linear copying and code validation limit output growth to exactly the input length (accounting for the conditional insertion), with explicit length checks halting processing on invalid codes to avoid overruns. Decoding remains efficient due to the fixed overhead properties of COBS, requiring no variable buffering.

Theoretical Aspects

Overhead Calculation

The overhead in Consistent Overhead Byte Stuffing (COBS) refers to the additional bytes added to the original packet during encoding, arising from the insertion of code bytes that indicate block lengths and ensure no zero bytes appear in the encoded stream before the . These code bytes replace skipped zero bytes or are inserted to split long sequences of non-zero bytes, with the total encoded length (excluding the final ) given by the number of non-zero input bytes plus the number of code bytes produced. In the worst case, which occurs when the input contains no zero bytes, the encoder inserts a code byte approximately every 254 data bytes to respect the maximum block size, yielding an overhead of \lceil n / 254 \rceil bytes for an n-byte input packet. This derivation follows from the constraint that each code byte can precede at most 254 non-zero data bytes before the next code or the implicit end (via the phantom zero), necessitating \lceil n / 254 \rceil such codes for a continuous non-zero sequence of length n. When zero bytes are present, they are skipped without output, allowing some code bytes to occupy their positions without increasing length, which reduces overhead relative to the worst case; however, any non-zero run exceeding 254 bytes still requires additional code insertions, computed as \lceil l / 254 \rceil - 1 splits for a run of length l. The overall worst-case bound of \lceil n / 254 \rceil holds regardless, as zeros can only decrease the need for splits. For average-case performance on uniformly random data—where each byte is zero with probability $1/256 (zero density ≈0.39%)—the expected overhead is approximately 0.23% of the packet size. Detailed probabilistic under this model yields an average expansion factor of approximately 1.0023. Overhead varies inversely with zero density, as higher densities provide more opportunities to skip bytes without added codes, while low densities approach the worst-case splitting requirement. The table below illustrates this for a representative 1000-byte packet across zero densities, using conceptual bounds from the encoding rules (exact values depend on run-length distributions, but extremes are precise).
Zero Density (%)Approximate Overhead (bytes)Explanation
04 (\lceil 1000/254 \rceil)No skips; maximum splits needed for one long non-zero run.
0.39 (random)~2.3Probabilistic analysis yields average expansion of 0.23%.
50 (e.g., alternating)0Equal non-zero and zero counts; codes replace zeros exactly, no splits.
1000All zeros skipped, replaced by 1000 codes of 0x01 (empty blocks), netting zero change.

Consistency Properties

Consistent Overhead Byte Stuffing (COBS) ensures a predictable worst-case overhead of at most \lceil n / 254 \rceil bytes (approximately 0.4%) for an n-byte packet, irrespective of the input data content, providing a bounded expansion factor that contrasts with escape-based stuffing methods where overhead can vary significantly based on the presence of specific byte patterns. This bounded overhead arises from the algorithm's design, which inserts a code byte at most once every 254 data bytes, leading to exactly 1 byte of overhead for packets up to 254 bytes in length. The predictability of this overhead facilitates efficient buffer management in decoding processes, allowing the receiver to pre-allocate a fixed amount of space equivalent to the input length plus \lceil n / 254 \rceil bytes without risk of overrun. This property is particularly advantageous in systems or resource-constrained environments, such as embedded networks, where dynamic buffer resizing or worst-case variability could introduce or failures. COBS further guarantees the absence of false delimiters by ensuring that the encoded output contains no zero bytes, thereby preventing unintended frame boundaries in continuous byte streams delimited by zeros. This is achieved through a substitution mechanism where every zero byte in the input is referenced and replaced via non-zero code bytes in the range 1 to 255, maintaining stream integrity without introducing extraneous zeros. A proof of this property follows from the encoding rule: input zeros are always mapped to positions indicated by subsequent non-zero codes, and all explicit codes are chosen from 1-255, ensuring the output stream remains free of delimiters except at intentionally placed boundaries.

Practical Examples

Basic Encoding Example

To illustrate the basic encoding process of Consistent Overhead Byte Stuffing (COBS), consider a simple input packet consisting of the binary sequence [0x01, 0x00, 0x02, 0x03, 0x00, 0x04]. This sequence contains zero bytes, which must be eliminated in the encoded output to allow 0x00 to serve as a reliable frame delimiter in serial transmission. The encoding begins by logically appending a phantom zero byte to the end of the input (not transmitted), ensuring the data is divisible into zero-terminated chunks. The extended sequence is thus [0x01, 0x00, 0x02, 0x03, 0x00, 0x04, 0x00] (1-based positions: 1=0x01, 2=0x00, 3=0x02, 4=0x03, 5=0x00, 6=0x04, 7=0x00). Processing proceeds from left to right, identifying runs of non-zero bytes terminated by a zero, and replacing each zero with a code byte indicating the length of the preceding run (specifically, the offset from the code byte position to the implicit zero position). Step 1: First chunk (positions 1–2)
Start at position 1. The next zero is at position 2. The code value is 2 (distance from code position 1 to zero position 2). Output the code byte 0x02, followed by the 1 non-zero byte at position 1 (0x01). The zero at position 2 is implicit and skipped. Current output: [0x02, 0x01]. Next block starts at position 3.
Step 2: Second chunk (positions 3–5)
From position 3, the next zero is at position 5. The code value is 3 (distance from code position 3 to zero position 5). Output the code byte 0x03, followed by the 2 non-zero bytes at positions 3–4 (0x02, 0x03). The zero at position 5 is implicit and skipped. Current output: [0x02, 0x01, 0x03, 0x02, 0x03]. Next block starts at position 6.
Step 3: Third chunk (positions 6–7)
From position 6, the next zero is the phantom at position 7. The code value is 2 (distance from code position 6 to zero position 7). Output the code byte 0x02, followed by the 1 non-zero byte at position 6 (0x04). The phantom zero is implicit and not output. Final encoded output: [0x02, 0x01, 0x03, 0x02, 0x03, 0x02, 0x04].
Input (with phantom zero):  01 00 | 02 03 00 | 04 00
                           ^           ^         ^
                           |           |         |
Code 0x02: 01 (1 byte)     Code 0x03: 02 03 (2 bytes)  Code 0x02: 04 (1 byte)
Output:                    02 01     03 02 03          02 04
This encoded sequence contains no zero bytes, confirming successful elimination for delimiter use. In practice, the full transmitted packet would be framed as 0x00 [encoded data] 0x00.

Decoding Example with Error Handling

To illustrate the decoding of a COBS-encoded packet, consider a sample encoded sequence derived from the original data bytes [0x01, 0x00, 0x02, 0x03, 0x00, 0x04], which was encoded as [0x02, 0x01, 0x03, 0x02, 0x03, 0x02, 0x04] followed by a 0x00 . The decoding process reverses the encoding by interpreting COBS code bytes and reconstructing the original data with inserted zeros. The decoding begins by reading the first code byte, 0x02, which indicates that 1 byte follows before a zero should be inserted. The next byte, 0x01, is copied directly, followed by the insertion of 0x00, yielding the partial output [0x01, 0x00]. The then advances past this code block and reads the next code byte, 0x03, meaning 2 bytes follow: 0x02 and 0x03 are copied, and 0x00 is inserted, extending the output to [0x01, 0x00, 0x02, 0x03, 0x00]. Finally, the code byte 0x02 is read, copying the remaining 1 byte 0x04 (without inserting a zero, as this indicates the end of the packet ), resulting in the full reconstructed [0x01, 0x00, 0x02, 0x03, 0x00, 0x04] before the . For error handling, COBS decoding includes checks to detect or malformed packets. If a byte of 0x00 is encountered (which is invalid, as codes range from 0x01 to 0xFF), the entire packet is discarded to prevent propagation of errors. Similarly, if the packet is too short—such as [0x03, 0x01], where only 1 byte follows a requiring 2—the flags it as invalid and discards it, as there are insufficient bytes to complete the block. In the presence of such errors, the zero-free nature of encoded data allows for immediate resynchronization upon detecting the next 0x00 . The following table visually compares the encoded input and decoded output, highlighting the role of flags in invalid cases:
ScenarioEncoded InputDecoded Output FlagNotes
Valid Packet[0x02, 0x01, 0x03, 0x02, 0x03, 0x02, 0x04] (before 0x00 )[0x01, 0x00, 0x02, 0x03, 0x00, 0x04]NoneSuccessful reconstruction with inserted zeros.
Invalid [0x00, 0x01, 0x02]N/ADiscard packet0x00 detected; invalid per COBS rules.
Short Packet[0x03, 0x01]N/ADiscard packetInsufficient bytes (needs 2 after ); malformation detected.
This example demonstrates how COBS decoding ensures reliable recovery while providing built-in error detection without additional checksums.

Applications and Implementation

Common Use Cases

Consistent Overhead Byte Stuffing (COBS) finds widespread application in serial communications within systems, particularly over UART or interfaces, where it enables efficient framing of sensor data packets without introducing variable overhead that could disrupt timing-critical transmissions. This approach is especially valuable in resource-constrained devices, such as microcontrollers, allowing reliable delineation of packets in noisy environments while maintaining low computational demands. In low-bandwidth networks, COBS serves as an effective alternative to protocols like SLIP or for packet framing, notably in ISM-band transmitters where it bounds overhead to approximately 0.4%, ensuring compliance with regulatory transmission time limits and supporting larger maximum transmission units (MTUs). This makes it suitable for portable devices in scenarios requiring unambiguous data delimitation over unreliable links. COBS is integrated into embedded control applications, such as those connecting devices to wireless interfaces via /, facilitating the transmission of up to 1 KB data blocks without necessitating or , often implemented directly in 8-bit for minimal footprint. In microcontroller ecosystems like , COBS libraries are utilized for packetizing commands and sensor readings over serial connections, providing a lightweight method to handle arbitrary binary payloads in hobbyist and prototyping projects.

Implementation Guidelines

When implementing Consistent Overhead Byte Stuffing (COBS), management is crucial to accommodate the encoding overhead without . Buffers should be sized to at least the input n plus \lceil n/254 \rceil bytes for the worst-case of approximately 0.4%, ensuring space for bytes and potential delimiters; for packets up to 254 bytes, this requires 1 additional byte. In-place encoding is feasible by processing the data sequentially from the end, overwriting the original as blocks are formed, which minimizes memory usage in resource-constrained environments. For language-specific integration, C and C++ are well-suited for embedded systems due to efficient pointer arithmetic, as demonstrated in reference implementations that traverse byte arrays directly to identify zero bytes and insert code values. In such setups, functions can operate on fixed-size char arrays or dynamically allocated buffers, leveraging standard library calls for memory handling. For prototyping or higher-level applications, Python offers straightforward bytearray handling, where mutable sequences allow in-place modifications during encoding loops, facilitating rapid development and testing of the core algorithms. Optimization strategies include using inline for performance-critical paths in microcontrollers, particularly for byte scanning and operations that benefit from processor-specific instructions to reduce cycle counts in systems. Handling variable packet lengths requires dynamic block chaining, where packets exceeding 254 bytes are split into multiple code blocks, with the encoder tracking positions to insert 0xFF milestones as needed. Testing implementations should emphasize unit tests for edge cases, such as a single-zero-byte packet, which encodes to a code byte of 0x01 followed by the delimiter, or longer all-zero sequences, which encode to repeated 0x01 code bytes, ensuring no decoding failures or buffer overruns occur. Integration with (CRC) enhances robustness by appending a after encoding but before framing, allowing error detection during transmission, as seen in protocols like PPP where a 16-bit verifies the stuffed data.

Comparisons and Alternatives

Comparison to Other Byte Stuffing Methods

Consistent Overhead Byte Stuffing (COBS) differs from other byte stuffing methods primarily in its bounded overhead and software simplicity, making it suitable for resource-constrained environments. (SLIP), defined in 1055, employs byte stuffing to frame packets by delimiting them with an END byte (0xC0) and escaping any occurrences of END or (0xDB) in the data using a two-byte sequence, resulting in variable overhead of 1 additional byte per escaped data byte. This can lead to significant inflation in worst-case scenarios, such as data streams with frequent END or bytes, potentially doubling the packet size if every byte requires escaping. In contrast, COBS guarantees a maximum overhead of at most 1 byte for packets up to 255 bytes, providing predictable sizing essential for fixed-buffer systems. Point-to-Point Protocol (PPP) and High-Level Data Link Control (HDLC) offer more established alternatives but with trade-offs in complexity and efficiency. PPP, as specified in RFC 1661, uses byte stuffing to escape the flag byte (0x7E) and control escapes (0x7D), yielding an average overhead of about 0.78% for random data but a worst-case of up to 100% in pathological cases like certain voice encodings. HDLC, a bit-oriented protocol standardized by ISO, employs bit stuffing to escape flag sequences (0x7E), limiting worst-case overhead to 20% for all-ones data, with an average of 1.6% for random inputs; however, its bit-level operations demand more complex hardware or software implementations compared to COBS's straightforward byte manipulations. COBS's byte-oriented design avoids bit shifting, enabling efficient software execution on embedded processors without specialized hardware. Other variants, such as Compressed SLIP (CSLIP) and compression, build on SLIP's framing to address overhead but retain some limitations. CSLIP integrates SLIP's byte stuffing with header compression techniques, reducing overall packet size for traffic over serial links, though the stuffing overhead remains variable and data-dependent. compression, outlined in RFC 1144, further optimizes TCP/ headers to as few as 3-5 bytes by exploiting redundancy, complementing byte stuffing in SLIP or but not altering the framing mechanism itself; it is particularly effective for low-bandwidth links with frequent small packets, yet introduces state management complexity. These methods suit scenarios with compressible headers, whereas COBS focuses solely on efficient, unambiguous framing without relying on protocol-specific assumptions.
MethodWorst-Case OverheadAverage Overhead (Random Data)ComplexitySuitability
COBS≤0.4% (≤1 byte for packets up to 255 bytes)0.23%Low (byte-oriented, software)Embedded, low-resource serial links
SLIPUp to 100%Low (~1-2%, variable)Low (simple escapes)Basic serial , but unpredictable size
PPPUp to 100%0.78%Medium (byte escapes)Point-to-point links, software-efficient
HDLC20%1.6%High (, hardware-preferred)High-speed synchronous links
CSLIP/Variable (stuffing) + header reductionReduced overall (~50% headers)Medium-high (compression state)Low-speed serial with / traffic
COBS is preferable for low-resource serial links, such as UARTs in embedded devices, where bounded overhead and minimal computational demands are critical, whereas or HDLC may be chosen for higher-speed or hardware-accelerated environments resembling Ethernet framing, and CSLIP/ for bandwidth-starved IP-over-serial applications.

Advantages and Limitations

Consistent Overhead Byte Stuffing (COBS) provides significant advantages in simplicity and efficiency for packet framing over byte-oriented transports. The algorithm requires only straightforward operations, such as scanning for byte positions and copying non-zero sequences, eliminating the need for complex lookup tables or escape mechanisms found in alternatives like byte stuffing. This makes COBS computationally inexpensive and easy to implement in both software and , particularly in resource-limited systems where minimal code size and processing cycles are critical. A key strength of COBS is its guaranteed low and consistent overhead, adding at most one byte for every 254 data bytes in the worst case—approximately 0.4% expansion—regardless of data content. This predictability benefits applications, such as communications, by avoiding the variable expansion (up to 100% in pathological cases) seen in methods like SLIP or , enabling higher effective throughput and larger maximum transmission units without risking frame overruns. For typical , the average overhead is even lower at about 0.23%, making it well-suited for protocols carrying arbitrary binary payloads. COBS supports arbitrarily large packet sizes while maintaining this overhead bound. COBS's design also facilitates hardware implementation through simple byte-level shifts and comparisons, supporting efficient integration into or FPGAs for high-speed links without dedicated stuffing circuitry. However, it lacks inherent error detection or correction capabilities, necessitating supplementary checks like to detect transmission errors and ensure reliability. Despite its bounds, COBS incurs relatively higher overhead for data with sparse zeros (e.g., text-like payloads), though still capped at 0.4%, and performs best on with frequent zeros where expansion can approach zero. Encoding and decoding require buffering up to 254 bytes per segment, presenting a between usage and the benefits of low in streaming scenarios. Given its efficiency and simplicity, COBS is used in low-power IoT networks and high-reliability serial links, including UART communications in embedded devices.

References

  1. [1]
    [PDF] Consistent Overhead Byte Stuffing - acm sigcomm
    This paper presents a new algorithm, called Consistent Overhead Byte Stuffing. (COBS), which can be relied upon to encode all packets efficiently, regardless of ...
  2. [2]
    [PDF] Consistent Overhead Byte Stuffing - Stuart Cheshire
    This paper presents a new byte stuffing algorithm, called Con- sistent Overhead Byte Stuffing (COBS), which tightly bounds the worst-case overhead. It ...Missing: Iain 2007
  3. [3]
    draft-ietf-pppext-cobs-00
    INTERNET DRAFT Consistent Overhead Byte Stuffing November 1997 receiver holds the three bytes of the partially received packet in the inactive buffer while ...
  4. [4]
    RFC 8163
    The solution is to encode the Data and 32-bit Data CRC fields before transmission using Consistent Overhead Byte Stuffing [COBS] and decode these fields upon ...
  5. [5]
    cobs - PyPI
    Consistent Overhead Byte Stuffing (COBS) ... Project description. Author: Craig McQueen. Contact: http://craig.mcqueen.id.au/; Copyright: 2010 Craig McQueen.
  6. [6]
    cmcqueen/cobs-c: Consistent Overhead Byte Stuffing - GitHub
    COBS is a method of encoding a packet of bytes into a form that contains no bytes with value zero (0x00). The input packet of bytes can contain bytes in the ...
  7. [7]
    Consistent overhead Byte stuffing - ACM Digital Library
    dissertation [9]. III. CONSISTENT OVERHEAD BYTE STUFFING ALGORITHMS. This section begins by describing the data-encoding format used by COBS, and the procedure ...
  8. [8]
    Consistent overhead byte stuffing - ACM Digital Library
    This paper presents a new byte stuffing algorithm, called Consistent Overhead Byte Stuffing (COBS), that tightly bounds the worst case overhead.
  9. [9]
    Help, My Serial Data Has Been Framed: How To Handle Packets ...
    Dec 11, 2011 · Most communications protocols deal in messages rather than streams: the bytes ... Consistent Overhead Byte Stuffing, which blew my approach away.
  10. [10]
    Library for Consistent Overhead Byte Stuffing (COBS) - GitHub
    This library implements the COBS algorithm. As the name says, the algorithm does byte stuffing. Byte stuffing means, that a byte in a stream or buffer is ...
  11. [11]
    PPP Consistent Overhead Byte Stuffing (COBS) - IETF
    This document defines the Consistent Overhead Byte Stuffing (COBS) negotiation and encapsulation procedure. Carlson expires May 1998 [Page 1] INTERNET DRAFT ...
  12. [12]
    RFC 1055: Nonstandard for transmission of IP datagrams over serial lines: SLIP
    ### Summary of SLIP Byte Stuffing Mechanism, Overhead, and Framing/Escaping from RFC 1055
  13. [13]
    Consistent overhead byte stuffing | IEEE Journals & Magazine
    This paper presents a new byte stuffing algorithm, called consistent overhead byte stuffing (COBS), which tightly bounds the worst-case overhead. It guarantees ...
  14. [14]
    RFC 1144 - Compressing TCP/IP Headers for Low-Speed Serial Links
    One design goal of the compression should be to limit the bandwidth demand of typing and ack traffic to at most 300 bps.
  15. [15]
    [PDF] Consistent Overhead Byte Stuffing - shiftleft.com
    Abstract—Byte stuffing is a process that encodes a sequence of data bytes that may contain 'illegal' or 'reserved' values, using a.