Netstring Decoder

Parses a netstring (`<byte-length>:<data>,`), validates the declared length and trailing comma, and returns the decoded text, the reverse of the netstring encoder. A free online tool from Staaarter, right in your browser.

Runs locallyUpdated 2026-07-22

Overview

Introduction

A netstring's length-prefixed format is easy for machines to parse but not something you can read at a glance. This tool strips the framing and gives you back the original text.

It also validates the framing along the way, catching a mismatched length or missing terminator instead of silently returning corrupted data.

What Is Netstring Decoder?

A netstring decoder that reads the leading decimal length, extracts exactly that many bytes of data, confirms a trailing comma follows, and decodes the result as UTF-8 text.

It's the exact reverse of the netstring encoder.

How Netstring Decoder Works

The tool parses the leading digits up to the first colon as the declared byte length, then slices that many bytes from the remaining UTF-8-encoded input.

It checks that the very next byte is a comma (the required terminator) before decoding the extracted bytes back to text; any mismatch produces a descriptive error.

When To Use Netstring Decoder

Use it when debugging a protocol or log that uses netstring framing and you need to read the actual message content.

It's also useful for validating that a hand-constructed netstring is correctly formed before sending it.

Features

Advantages

  • Validates both the declared length and the terminator, not just a best-effort parse.
  • Decodes using UTF-8, matching the encoder's byte-based length.
  • Slices the declared count out of a UTF-8 byte array rather than out of the raw string, so multi-byte characters are counted exactly as the format specifies.

Limitations

  • Decodes one netstring at a time, not a concatenated stream of several.
  • Doesn't recover data if the original length prefix was already wrong when written.

Examples

Decoding a netstring

Input

13:Hello, world!,

Output

Hello, world!

13 bytes are read after the colon, the trailing comma is confirmed, and the result is decoded as text.

Best Practices & Notes

Best Practices

  • Check the reported error carefully; a length mismatch usually points to a bug in whatever produced the netstring.
  • Use alongside Convert a String to a Netstring to test round-trip encoding and decoding.
  • Treat a length mismatch as a bug in whatever produced the netstring rather than adjusting the prefix by hand, since that length is the format's only framing signal.

Developer Notes

Because the declared length is in bytes, slicing happens on a UTF-8-encoded Uint8Array of the remaining input rather than on the raw JavaScript string, avoiding the same code-unit-vs-byte mismatch that the encoder guards against.

Netstring Decoder Use Cases

  • Decoding a netstring-framed message while debugging a protocol
  • Validating a hand-constructed netstring before sending it
  • Reading netstring-formatted log entries

Common Mistakes

  • Assuming a decode failure means the data is corrupted, when it may just mean the length was computed in characters instead of bytes.
  • Trying to decode multiple concatenated netstrings at once.

Tips

  • If decoding fails, re-encode the original text with the encoder tool and compare the length prefixes.
  • A netstring carrying non-ASCII text always shows a length prefix larger than its visible character count, which is expected rather than a sign of corruption.

References

Frequently Asked Questions