Skip to content
Main menu
  • Main page
  • Discover
  • Unexpected connections
  • Topics
  • Random article
  • Search
Your library
  • Saved articles
  • Recent discoveries
  • Rabbit-hole trails
Topic areas
  • Computer Science
  • Mathematics
  • Physics
  • Engineering
  • Biology
  • Economics
  • Curiosities
WikiholeDeeper into Wikipedia
EnglishEN
  • Saved
  • History

  • Article text and media come live from Wikipedia via the official MediaWiki API and are available under the Creative Commons Attribution-ShareAlike 4.0 License; additional terms may apply. Each article links to its source and revision.
  • WikiHole is an independent project and is not affiliated with the Wikimedia Foundation.
  • How ranking works
  • All topics
  • Reading history
  • Random article
  • MediaWiki API

Consistent Overhead Byte Stuffing

  • Article
  • Rabbit hole
  • Read
  • View history
Tools
Actions
  • Read
  • View history
General
  • Recent changes
  • Related articles
  • Random discovery
This article
Reading time
5 min
Topic
Computer Science
Quality
C-class
Views
884 in 14 days
Last edited
20 Oct 2026
Print/export
  • Printable version
In other projects
  • Wikidata item
From Wikipedia, the free encyclopedia
Rabbit hole:
  1. Consistent Overhead Byte Stuffing

Consistent Overhead Byte Stuffing (COBS) is an algorithm for encoding data bytes that results in efficient, reliable, unambiguous packet framing regardless of packet content, thus making it easy for receiving applications to recover from malformed packets. It employs a particular byte value, typically zero, to serve as a packet delimiter (a special value that indicates the boundary between packets). When zero is used as a delimiter, the algorithm replaces each zero data byte with a non-zero value so that no zero data bytes will appear in the packet and thus be misinterpreted as packet boundaries.

Byte stuffing is a process that transforms a sequence of data bytes that may contain 'illegal' or 'reserved' values (such as packet delimiter) into a potentially longer sequence that contains no occurrences of those values. The extra length of the transformed sequence is typically referred to as the overhead of the algorithm. HDLC framing is a well-known example, used particularly in PPP (see RFC 1662 § 4.2). Although HDLC framing has an overhead of <1% in the average case, it suffers from a very poor worst-case overhead of 100%; for inputs that consist entirely of bytes that require escaping, HDLC byte stuffing will double the size of the input.

The COBS algorithm, on the other hand, tightly bounds the worst-case overhead. COBS requires a minimum of 1 byte overhead, and a maximum of ⌈n/254⌉ bytes for n data bytes (one byte in 254, rounded up). Consequently, the time to transmit the encoded byte sequence is highly predictable, which makes COBS useful for real-time applications in which jitter may be problematic. The algorithm is computationally inexpensive, and in addition to its desirable worst-case overhead, its overhead is also low compared to other unambiguous framing algorithms like HDLC. COBS does, however, require up to 254 bytes of . Before transmitting its first byte, it needs to know the position of the first zero byte (if any) in the following 254 bytes.

average
1
2
lookahead

A 1999 Internet Draft proposed to standardize COBS as an alternative for HDLC framing in PPP, due to the aforementioned poor worst-case overhead of HDLC framing.3

Loading the rest of the article…

Recent changes

Rabbit hole

Where Consistent Overhead Byte Stuffing leads. Every connection below has a source: a link in this article, a shared Wikipedia category, or CirrusSearch text similarity. Articles already on your trail are left out.

Contents
  • (Top)
  • Packet framing and stuffing
  • Encoding examples
  • Implementation
  • See also
  • References
  • External links
  • Recent changes
  • Rabbit hole
Contents
Contents8 sections
  • (Top)
  • Packet framing and stuffing
  • Encoding examples
  • Implementation
  • See also
  • References
  • External links
  • Recent changes
  • Rabbit hole
Study aids for Consistent Overhead Byte Stuffing

Terminology

COBS
Consistent Overhead Byte Stuffing (COBS) is an algorithm for encoding data bytes that results in efficient, reliable, unambiguous packet framing regardless of packet content, thus making it easy for receiving applications to recover from malformed packets.
Byte stuffing
Byte stuffing is a process that transforms a sequence of data bytes that may contain 'illegal' or 'reserved' values (such as packet delimiter) into a potentially longer sequence that contains no occurrences of those values.
Prefixed block description
Prefixed block description: To encode some bytes, first append a zero byte, then break them into groups of either 254 non-zero bytes, or 0–253 non-zero bytes followed by a zero byte.
Linked list description
Linked list description: First, insert a zero byte at the beginning of the packet, and after every run of 254 non-zero bytes.

Terms the article defines in bold, quoted in context.

Categories:
  • Encodings
  • Computer network technology
  • Link protocols
  • Logical link control
  • Telecommunications standards
  • Telecommunication protocols
  • Networking standards

1,045 words · 3 references · revision 1381166697 · CC BY-SA 4.0

General
  • Recent changes
  • Related articles
  • Random discovery
This article
Reading time
5 min
Topic
Computer Science
Quality
C-class
Views
884 in 14 days
Last edited
20 Oct 2026

Key concepts

  • Point-to-point protocol2
  • Algorithm1
  • Packet (information technology)1
  • Delimiter1
  • Overhead (computing)1
  • High-Level Data Link Control1
  • Internet Draft1
  • Communications protocol1
  • Payload (computing)1
  • Trailing zero1

The articles this one links to most, weighted towards the introduction.

Print/export
  • Printable version
In other projects
  • Wikidata item

Packet framing and stuffing

When packetized data is sent over any serial medium, some protocol is required to demarcate packet boundaries. This is done by using a framing marker, a special bit-sequence or character value that indicates where the boundaries between packets fall. Data stuffing is the process that transforms the packet data before transmission to eliminate all occurrences of the framing marker, so that when the receiver detects a marker, it can be certain that the marker indicates a boundary between packets.

COBS transforms an arbitrary string of bytes in the range [0,255] into bytes in the range [1,255]. Having eliminated all zero bytes from the data, a zero byte can now be used to unambiguously mark the end of the transformed data. This is done by appending a zero byte to the transformed data, thus forming a packet consisting of the COBS-encoded data (the payload) to unambiguously mark the end of the packet.

(Any other byte value may be reserved as the packet delimiter, but using zero simplifies the description.)

Consistent Overhead Byte Stuffing (COBS) encoding process
Consistent Overhead Byte Stuffing (COBS) encoding process

There are two equivalent ways to describe the COBS encoding process:

Prefixed block description
To encode some bytes, first append a zero byte, then break them into groups of either 254 non-zero bytes, or 0–253 non-zero bytes followed by a zero byte. Because of the appended zero byte, this is always possible.
Encode each group by deleting the trailing zero byte (if any) and prepending the number of non-zero bytes, plus one. Thus, each encoded group is the same size as the original, except that 254 non-zero bytes are encoded into 255 bytes by prepending a byte of 255.
As a special exception, if a packet ends with a group of 254 non-zero bytes, it is not necessary to add the trailing zero byte. This saves one byte in some situations.
Linked list description
First, insert a zero byte at the beginning of the packet, and after every run of 254 non-zero bytes. This encoding is obviously reversible. It is not necessary to insert a zero byte at the end of the packet if it happens to end with exactly 254 non-zero bytes.
Second, replace each zero byte with the offset to the next zero byte, or the end of the packet. Because of the extra zeros added in the first step, each offset is guaranteed to be at most 255.

Encoding examples

These examples show how various data sequences would be encoded by the COBS algorithm. In the examples, all bytes are expressed as hexadecimal values, and encoded data is shown with text formatting to illustrate various features:

  • Bold indicates a data byte which has not been altered by encoding. All non-zero data bytes remain unaltered.
  • Green indicates a zero data byte that was altered by encoding. All zero data bytes are replaced during encoding by the offset to the following zero byte (i.e. one plus the number of non-zero bytes that follow). It is effectively a pointer to the next packet byte that requires interpretation: if the addressed byte is non-zero then it is the following group header byte zero data byte that points to the next byte requiring interpretation; if the addressed byte is zero then it is the end of packet.
  • Red is an overhead byte which is also a group header byte containing an offset to a following group, but does not correspond to a data byte. These appear in two places: at the beginning of every encoded packet, and after every group of 254 non-zero bytes.
  • A blue zero byte appears at the end of every packet to indicate end-of-packet to the data receiver. This packet delimiter byte is not part of COBS proper; it is an additional framing byte that is appended to the encoded output.
ExampleUnencoded data (hex)Data bytesEncoded with COBS (hex)
100101 01 00
200 00201 01 01 00
300 11 00301 02 11 01 00
411 22 00 33403 11 22 02 33 00
511 22 33 44405 11 22 33 44 00
6

Implementation

The following code implements a COBS encoder and decoder in the C programming language, processing data byte by byte.

#include <stddef.h>
#include <stdint.h>
#include <assert.h>

/** COBS encode data to buffer
	@param data Pointer to input data to encode
	@param length Number of bytes to encode
	@param buffer Pointer to encoded output buffer
	@return Encoded buffer length in bytes
	@note Does not output delimiter byte
*/
size_t cobsEncode(const void *data, size_t length, uint8_t *buffer)
{
	assert(data && buffer);

	uint8_t *encode = buffer; // Encoded byte pointer
	uint8_t *codep = encode++; // Output code pointer
	uint8_t code = 1; // Code value

	for (const uint8_t *byte = (const uint8_t *)data; length--; ++byte)
	{
		if (*byte) // Byte not zero, write it
			*encode++ = *byte, ++code;

		if (!*byte || code == 0xff) // Input is zero or block completed, restart
		{
			*codep = code, code = 1, codep = encode;
			if (!*byte || length)
				++encode;
		}
	}
	*codep = code; // Write final code value

	return (size_t)(encode - buffer);
}

/** COBS decode data from buffer
	@param buffer Pointer to encoded input bytes
	@param length Number of bytes to decode
	@param data Pointer to decoded output data
	@return Number of bytes successfully decoded
	@note Stops decoding if delimiter byte is found
*/
size_t cobsDecode(const uint8_t *buffer, size_t length, void *data)
{
	assert(buffer && data);

	const uint8_t *byte = buffer; // Encoded input byte pointer
	uint8_t *decode = (uint8_t *)data; // Decoded output byte pointer

	for (uint8_t code = 0xff, block = 0; byte < buffer + length; --block)
	{
		if (block) // Decode block byte
			*decode++ = *byte++;
		else
		{
			block = *byte++;             // Fetch the next block length
			if (block && (code != 0xff)) // Encoded zero, write it unless it's delimiter.
				*decode++ = 0;
			code = block;
			if (!code) // Delimiter code found
				break;
		}
	}

	return (size_t)(decode - (uint8_t *)data);
}

See also

  • Bit stuffing
  • Serial Line Internet Protocol

References

  1. 1Cheshire, Stuart; Baker, Mary (April 1999). "Consistent Overhead Byte Stuffing" (PDF). IEEE/ACM Transactions on Networking. 7 (2): 159–172. CiteSeerX 10.1.1.108.3143. doi:10.1109/90.769765. S2CID 47267776. Retrieved November 30, 2015. {{cite journal}}: Cite uses deprecated parameter |citeseerx= (help)
  2. 2Cheshire, Stuart; Baker, Mary (17 November 1997). Consistent Overhead Byte Stuffing (PDF). ACM SIGCOMM '97. Cannes. Retrieved November 23, 2010.
  3. 3Carlson, James; ; Baker, Mary (November 1997). . . I-D draft-ietf-pppext-cobs-00.txt.

External links

  • Python implementation
  • Alternate C implementation
  • Another implementation in C
  • Consistent Overhead Byte Stuffing—Reduced (COBS/R)
  • A patent describing a scheme with a similar result but using a different method
11 00 00 00
4
02 11 01 01 01 00
701 02 03 ... FD FE254FF 01 02 03 ... FD FE 00
800 01 02 ... FC FD FE25501 FF 01 02 ... FC FD FE 00
901 02 03 ... FD FE FF255FF 01 02 03 ... FD FE 02 FF 00
1002 03 04 ... FE FF 00255FF 02 03 04 ... FE FF 01 01 00
1103 04 05 ... FF 00 01255FE 03 04 05 ... FF 02 01 00

Below is a diagram using example 4 from above table, to illustrate how each modified data byte is located, and how it is identified as a data byte or an end of frame byte.

   [OHB]                                : Overhead byte (Start of frame)
     3+ -------------->|                : Points to relative location of first zero symbol
                       2+-------->|     : Is a zero data byte, pointing to next zero symbol
                                  [EOP] : Location of end-of-packet zero symbol.
     0     1     2     3     4    5     : Byte Position
     03    11    22    02    33   00    : COBS Data Frame
           11    22    00    33         : Extracted Data
     
OHB = Overhead Byte (Points to next zero symbol)
EOP = End Of Packet

Examples 7 through 10 show how the overhead varies depending on the data being encoded for packet lengths of 255 or more.

Cheshire, Stuart
PPP Consistent Overhead Byte Stuffing (COBS)
IETF
Created
23 Nov 2010
History
163 edits
66 contributors
2 edits in the last 30 days
Last edited
20 Oct 2026

163 revisions in total · 66 contributors · +11 / −11 bytes across 2 edits by 1 contributor in the last 30 days

  1. 20 Oct 2026, 11:56 UTCTemporary accounttest−11diff
  2. 20 Oct 2026, 11:55 UTCTemporary accountrevertedtest+11diff
  3. 23 Mar 2026, 10:19 UTCTemporary account§ Encoding examples Explicitly state number of data bytes for each example+55diff
  4. 14 Oct 2025, 19:43 UTCPorkStock§ growthexperiments-addlink-summary-summary:2|1|0+35diff
  5. 1 Sept 2025, 15:19 UTCNeøn§ External links Categories+220diff
  6. 29 May 2025, 15:49 UTCAnonymous contributorI deleted the "possibly faster" example because it does not successfully encode + decode the example payloads from this page. See https://gist.github.com/charlesnicholson/4c370c9b7d7cdb6f73caae5b4d31dd85 for a standalone .c file you can compile and run to see the failures.−2,056diff
  7. 20 May 2025, 05:37 UTCAnonymous contributor§ Implementation+2,086diff
  8. 7 Sept 2024, 19:35 UTCAngeld23mNo edit summary+25diff

View full revision history

Created
23 Nov 2010
History
163 edits
66 contributors
2 edits in the last 30 days
Last edited
20 Oct 2026

Go deeper: linked from this article

  • Linked from the introduction

    High-Level Data Link Control

    Communications protocol

    High-Level Data Link Control (HDLC) is a communication protocol used for transmitting data between devices in telecommunication and networking.

    15 min readGo deeper
  • Linked from the introduction

    Algorithm

    Sequence of operations for a task

    In mathematics and computer science, an algorithm is a finite sequence of mathematically rigorous instructions, typically used to solve a class of specific problems or to perform a computation.

    25 min readGo deeper
  • Linked from the introduction

    Point-to-Point Protocol

    Data link layer communication protocol

    In computer networking, Point-to-Point Protocol (PPP) is a data link layer (layer 2) communication protocol between two routers directly without any host or any other networking in between.

    8 min readGo deeper
  • Linked from the introduction

    Delimiter

    Character(s) for specifying the boundary between regions of data

    In computing, a delimiter is a character or a sequence of characters for specifying the boundary between separate, independent regions in data such as a text file or data stream.

    11 min readGo deeper
  • Listed under See also

    Serial Line Internet Protocol

    Internet Protocol encapsulation for serial ports and router connections

    The Serial Line Internet Protocol (SLIP) is an encapsulation of the Internet Protocol designed to work over serial ports and router connections. It is documented in RFC 1055.

    3 min readGo deeper
  • Linked from the introduction

    Internet Draft

    Document published by the IETF

    An Internet Draft (I-D) is a document published by the Internet Engineering Task Force (IETF) containing preliminary technical specifications, results of networking-related research, or other technical information.

    1 min readGo deeper
  • Linked from the introduction

    Overhead (computing)

    Consumption of resources that is indirectly required to achieve a goal

    In computing, overhead is the consumption of computing resources for aspects that are not directly related to achieving a desired goal.

    3 min readGo deeper
  • Linked from the introduction

    Network packet

    Formatted unit of data carried by a packet-switched network

    In telecommunications and computer networking, a network packet is a formatted unit of data carried by a packet-switched network.

    4 min readGo deeper
  • Listed under See also

    Bit stuffing

    Practice in data transfers

    In data transmission and telecommunications, bit stuffing (also known—uncommonly—as positive justification) is the insertion of non-information bits into data.

    2 min readGo deeper

Adjacent: shared categories and similar text

  • Linked in “Packet framing and stuffing”

    Trailing zero

    Zero after the final non-zero digit of a number

    A trailing zero is any 0 digit that comes after the last nonzero digit in a number string in positional notation.

    2 min readGo deeper
  • Linked in “Packet framing and stuffing”

    Communication protocol

    System for exchanging messages between computing systems

    A communication protocol is a system of rules that allows two or more entities of a communications system to transmit information.

    24 min readGo deeper
  • Linked in “Encoding examples”

    Hexadecimal

    Base-16 numeric representation

    Hexadecimal (or hex for short) is a positional numeral system for representing a numeric value as base 16.

    24 min readGo deeper
  • Linked in “Implementation”

    The C Programming Language

    Book by Brian Kernighan and Dennis Ritchie

    The C Programming Language (sometimes termed K&R, after its authors' initials) is a computer programming book written by Brian Kernighan and Dennis Ritchie, the latter of whom originally designed and…

    4 min readGo deeper
  • Linked in “Packet framing and stuffing”

    Payload (computing)

    Content of a message excluding headers and metadata

    In computing and telecommunications, the payload is the part of transmitted data that is the actual intended message.

    1 min readGo deeper