A netstring is a tiny, self-describing way to wrap a string so a parser always knows exactly where it ends. Invented by Daniel J. Bernstein, it is widely used in protocols like SCGI and in qmail. This tool encodes any text into a netstring and decodes netstrings back to their payload, all in your browser.
How it works
A netstring has the shape [byte-length]:[data],:
- Encoding measures the data in UTF-8 bytes (not characters) using
TextEncoder, then writes that count in ASCII decimal. - It appends a colon
:, the raw data, and a trailing comma,. - Decoding reads digits up to the colon to learn the declared length, slices exactly that many bytes of payload, and then requires a comma immediately after — otherwise the netstring is rejected as malformed.
Because the length is known up front, the payload may contain any bytes, including :, ,, and null, with no escaping needed.
Tips and examples
The string hello encodes to 5:hello,. An empty string is the perfectly valid 0:,. The 4-byte emoji sequence 😀 encodes to 4:😀, because the length counts bytes, not the single visible character. When decoding, a prefix length that does not match the real payload length is flagged as an error so you can spot truncated or corrupted data.