COBS Encoder / Decoder

Encode a packet with Consistent Overhead Byte Stuffing — the byte stuffing that guarantees no 00 byte appears inside a frame — or decode a COBS frame you captured from a link.

Mode

Type the packet bytes in hexadecimal. Spaces, commas and line breaks are ignored.

COBS is the byte stuffing used to frame packets on serial and embedded links. The encoder appends a phantom zero to the packet, cuts it at every zero byte into chunks of at most 254 bytes, and writes each chunk as one code block: a code byte n followed by the n − 1 non-zero data bytes and an implied zero. A code byte of FF is the exception — it carries 254 data bytes and no implied zero, so a long run without a zero is split into full blocks. Because zero is never used as a code byte and never appears in the data, a single 00 can mark the end of every frame. Decoding walks the code bytes, copies n − 1 bytes each time and restores the implied zero, except after the final block, where that zero is the phantom byte and not part of the packet. The cost is at most one byte per 254 bytes of data, and every packet of 254 bytes or less costs exactly one byte; a packet of all zeroes is the worst case, since each zero becomes its own code block. This page implements the reference listings in the paper, without its optional trailing-block optimisation, so a packet ending in an exact run of 254 non-zero bytes costs one byte more than the published bound. A frame never contains 00; if you paste one, the trailing delimiter is removed for you and any other 00 is reported as an error. Everything runs in your browser; nothing is sent or stored.