> ## Content Index
> Fetch the complete content index at: https://datajutsu.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# Protobuf Bytes and String Are the Same Wire Format (and the JSON Is Where They Split)
- URL: https://datajutsu.com/protobuf-bytes-vs-string/
- Published: 2026-10-23T02:16:54.000Z
- Updated: 2026-10-23T02:16:54.000Z
- Author: Data Jutsu

String and bytes are the one type pair where the schema label is the whole difference, because on the wire they are the same thing. A field that says string s = 1 and a field that says bytes s = 1 write identical bytes for the same content: both are a length-delimited value, tag plus length plus payload. I encoded hi in both and got the same four bytes, 0a026869, and decoded the same four bytes back under each schema. One gives you the string hi, the other gives you the Base64 aGk=. Nothing in the bytes tells you which it is. The wire format has no string marker and no bytes marker, just a run of bytes with a declared length, exactly as described in the [wire format post](https://datajutsu.com/how-protobuf-wire-format-works/).

The label matters the moment the content stops being text. A string field is UTF-8 by definition, so the same visual value can change size: the six characters of héllo encode as six UTF-8 bytes, 0a0668c3a96c6c6f, because the é takes two. A bytes field has no such rule; \[0, 255, 16\] encodes as 0a0300ff10 with zero opinion about what the bytes mean. Feed those same three bytes back through a string schema and you get a string with a null character and two replacement characters, because the UTF-8 decoder has to do something with 0xff 0x10\. Feed them through a bytes schema and you get the clean Base64 AP8Q. Same wire, two readings, and only the schema tells the reader which one to use.

The JSON mapping is where the split becomes a real interop decision, and the two directions behave differently. On the way out, bytes come as a Base64 string and a plain string comes as itself, so a bytes field that happens to contain the UTF-8 encoding of hi prints as aGk= while a string field prints as hi. On the way in it gets stranger, and this one is asymmetric. A bytes field fed aGk= decodes the Base64 and encodes the two original bytes. The same value, aGk=, fed to a string field is kept literally, four characters, 0a0461476b3d, no decoding at all. And a Base64 string that is not valid, like plain hi on a bytes field, does not error: it silently encodes one byte, 0a0186, and round trips without complaint. The input side of the mapping assumes you meant Base64 and does not check, which is the exact kind of silent loss the int64 and empty-array posts are about.

The encoders also disagree about emptiness, and the difference is measurable. An empty string and an absent field encode to zero bytes in the real C++ encoder; protoc 25.3 with s set to the empty string writes nothing, the field is simply not on the wire. The JS library writes a different answer: an explicitly empty string encodes as 0a00, the tag and a length of zero, a field that announces itself and then carries nothing. Absent and undefined still encode to zero bytes the same way, so the library's rule is explicit empty is present-but-empty, which matches what the decoder already does elsewhere. Both forms decode back to an empty string, so the wire still interoperates, but a diff tool that counts bytes will see the two encoders produce different lengths for what both consider the same value.

In the descriptor, the difference is one number. The field's type field carries 9 for a string and 12 for bytes, and that is the entire distinction the compiler's metadata records. Both ride the same length-delimited wire type, so a tool that only looks at wire types, which is what a raw decode with no schema does, cannot tell them apart. The raw decode tab shows the bytes and flags them as text where they happen to be valid UTF-8 or Base64 where they are not, which is the best effort the format allows. The check that actually settles a string-versus-bytes question is the same one that settles any unknown field: reconstruct the schema from the data, encode, and diff the bytes against the original, because the schema is the only place the distinction lives.

The tool handles both sides of the split without you asking. The encode tab takes a string value on a string field and Base64 or a byte array on a bytes field and writes the same wire format either way, and the decode tab hands back the JSON mapping, plain string or Base64, according to the schema you paste. The generated code keeps the distinction honest too: a bytes field becomes \[\]byte in Go, a Base64-contentEncoded string in the JSON Schema, a real byte type elsewhere, while a string stays a string in every target. The converter with the parser this post measured is at [proto.datajutsu.com](https://proto.datajutsu.com/?ref=datajutsu.com), and the JSON rules it follows are in the [JSON mapping post](https://datajutsu.com/protobuf-json-mapping/).