Protobuf vs JSON: Size, Speed and Trade-offs
Measured on 1,000 records: Protobuf is 44.6% of JSON's size, but after Brotli the gap vanishes. Wire format, speed caveats and when JSON still wins.
"Protobuf is smaller and faster than JSON" is the sentence every comparison repeats. It is half true, and the half that is false is the half that decides your architecture.
So this article does two things. First it explains the wire format from the official specification, because the size difference is a direct consequence of three encoding rules. Then it reports numbers I measured myself on this machine — 1,000 records, three different payload shapes, raw and compressed — including two results that contradict the usual advice.
Every number below is reproducible. The method and environment are stated in section 2, and the Order-shape rows are published as raw data at /benchmarks so you can diff my tables against the file itself.
The short version
| Question | Answer from measurement |
|---|---|
| Is Protobuf smaller? | Yes for structured data: 44.6% of JSON's bytes on a mixed-type record |
| Is it still smaller after compression? | No. After Brotli-11, Protobuf was 100.7% of Brotli'd JSON — slightly larger |
| Does it help string-heavy payloads? | Barely: 99.3% of JSON's size when the payload is mostly text |
| Is it faster in JavaScript? | Encoding, no — JSON.stringify was 1.6–1.9× faster. Decoding, narrowly — protobufjs was 1.1–1.3× faster |
| Where does it win biggest? | Tiny numeric messages: 32.8% of JSON's size |
| When should you keep JSON? | Human-readable configs, browser APIs, debugging, anything string-dominated |
1. Why the wire format is smaller
Three rules from the official encoding guide explain almost the entire size difference.
Rule one: field names never travel. The binary format identifies a field by number, not by name:
"The binary version just uses the field's number as the key."
In JSON, "customerEmail" costs 15 bytes every single time it appears. In Protobuf it costs one byte of tag, once per field, regardless of how long the name is.
Rule two: the tag packs two things into one varint. From the same guide, the tag is:
(field_number << 3) | wire_type
There are six wire types: VARINT (0), I64 (1), LEN (2), SGROUP (3), EGROUP (4), I32 (5). So field 1 carrying a string is tag 0x0A — (1 << 3) | 2 = 10. One byte tells the decoder both which field this is and how to read it.
Rule three: small integers cost one byte. Varints use:
"one and ten bytes, with small values using fewer bytes"
A value of 1 is a single byte. A value of 300 is two bytes (AC 02). Signed fields can use ZigZag, where "positive p becomes 2 * p and negative n becomes 2 * |n| - 1", so -1 also encodes to one byte instead of ten.
Strings and bytes use the LEN wire type, with a "varint immediately after the tag" giving the payload length. That length prefix is the only overhead a string pays.
A real byte-level example
Here is an actual message, encoded with protobufjs 8.8.0 and dumped as hex:
syntax = "proto3";
message Tiny {
string id = 1;
int64 ts = 2;
int32 status = 3;
}
Encoding { id: "e0", ts: 1762900000000, status: 0 } produces 11 bytes:
0A 02 65 30 10 80 FA 9C A8 A7 33
Read it left to right:
| Bytes | Meaning |
|---|---|
0A |
tag: field 1, wire type 2 (LEN) |
02 |
length: 2 bytes follow |
65 30 |
the ASCII for e0 |
10 |
tag: field 2, wire type 0 (VARINT) |
80 FA 9C A8 A7 33 |
varint for 1762900000000 |
Notice what is missing: status. It was 0, and proto3 does not put default values on the wire:
"If a scalar message field is set to its default, the value will not be serialized on the wire."
Set status: 2 and the message grows to 13 bytes, appending 18 02. The same record as JSON is 41 bytes — 3.7× larger, and that gap is almost entirely the field names and the quotes.
This is also why Protobuf is not self-describing. Without the .proto file, 0A 02 65 30 is just bytes. JSON carries its own schema in every message; Protobuf carries it in a separate contract you must distribute. That trade is the whole design.
2. Measured: three payload shapes
Numbers from a benchmark I ran locally, not from someone else's blog.
Method. Node.js v24.22.0 on Windows x64, protobufjs 8.8.0, Node's built-in zlib for gzip and Brotli. 1,000 records per shape, generated from a seeded LCG (seed 20261112) so every run produces identical bytes. Timings are the median of 15 rounds after 2 warmup rounds. Compression is gzip level 6 and Brotli quality 11. The Order-shape byte counts, its four serialization timings and every JSON compressed size below are rows of the dataset published at /benchmarks, produced by the bench.mjs you can download there. The Protobuf compressed sizes are not in that dataset — they came from a one-off script using the same seeded generator and the same Node zlib, so treat them as a spot check rather than something you can re-run from the published file.
Three shapes, chosen to separate the effects:
- Order — mixed types: strings,
int64,double,bool, an enum, a nested message, arepeatedlist, amap, and a 32-bytebytesfield. This is what a real API record looks like. - Tiny —
string id,int64 ts,int32 status. Numeric-dominated, minimal text. - TextBlob —
string idplus a ~2 KB text body. String-dominated.
| Payload | JSON | Protobuf | Protobuf as % of JSON |
|---|---|---|---|
| Order (mixed) | 553,706 B | 246,928 B | 44.6% |
| Tiny (numeric) | 43,891 B | 14,390 B | 32.8% |
| TextBlob (2 KB strings) | 2,050,891 B | 2,035,890 B | 99.3% |
The spread is the point. The "Protobuf is 3× smaller" claim is only true for numeric-heavy structured data. When your payload is mostly text, Protobuf saves you the field names and nothing else — 0.7% here. If you are serializing article bodies, log lines, or LLM outputs, switching formats buys you almost nothing.
One more detail worth knowing: Protobuf's length-delimited stream (a varint length prefix before each message, as gRPC and Kafka carry it) was 248,928 B versus 246,928 B for the bare concatenation. The framing costs 2,000 bytes across 1,000 records — 2 bytes per message. Budget for it.
3. The compression twist
Here is the result that changed my mind about the usual advice. I compressed both formats and compared again:
| Payload | gzip-6 JSON | gzip-6 Protobuf | Protobuf as % | Brotli-11 JSON | Brotli-11 Protobuf | Protobuf as % |
|---|---|---|---|---|---|---|
| Order | 52,145 B | 45,341 B | 87.0% | 27,870 B | 28,077 B | 100.7% |
| Tiny | 5,167 B | 3,672 B | 71.1% | 1,882 B | 2,534 B | 134.6% |
| TextBlob | 10,290 B | 10,052 B | 97.7% | 1,817 B | 1,679 B | 92.4% |
Read the Order row again. Raw, Protobuf is 44.6% of JSON. After Brotli-11, Protobuf is 0.7% larger than JSON.
The reason is structural. JSON's redundancy — repeated field names, repeated punctuation, repeated enum strings — is exactly what a dictionary-based compressor eats for breakfast. Brotli removes it almost for free. Protobuf already removed that redundancy at encoding time, so there is less left for the compressor to find, and its varint-packed binary is comparatively high-entropy.
The Tiny row is worse: after Brotli, Protobuf is 34.6% larger than JSON. A thousand small numeric records compress to 1,882 bytes as JSON but 2,534 as Protobuf.
The practical consequence: if your transport already compresses — and HTTP with Content-Encoding: br or gzip does — then Protobuf's size advantage largely disappears. You are paying the schema-distribution cost, the tooling cost, and the loss of human readability for a benefit that compression already gave you for free.
Protobuf still wins on the wire when compression is not applied: gRPC streams, Kafka topics, Redis values, embedded devices, anything where you pay per byte and cannot afford a decompression step. That is a real and common case. It is just not the case most web APIs are in.
4. Speed: the JavaScript caveat
The other half of the usual claim is "Protobuf is faster". In JavaScript, with the library most people actually use, my measurements say otherwise.
| Operation (Order, 1,000 records) | Protobuf (protobufjs) |
JSON (native) |
|---|---|---|
| Serialize | 9.19 ms | 4.88 ms |
| Deserialize | 3.52 ms | 4.53 ms |
JSON.stringify and JSON.parse are native C++ inside V8. protobufjs is JavaScript doing varint arithmetic, buffer allocation and object construction. Encoding shows that difference plainly: JSON.stringify finished in 4.88 ms against protobufjs's 9.19 ms, and the second run of the same script gave 6.31 ms against 10.35 ms. JSON won both, by 1.88× and 1.64×.
Decoding is a much narrower win. The published harness gave 3.52 ms for Order.decode against 4.53 ms for JSON.parse, and a second full run of the same script gave 4.39 ms against 4.87 ms — Protobuf ahead by 1.29× and 1.11×. So the direction is real, but the margin is small, and it sits inside the noise on these timings: the two runs disagree with each other by 7.6%–29.5% across the four numbers. A separate, lighter script once put the pair 0.02 ms apart. What JavaScript Protobuf decoding actually buys you is roughly 10–30%, not the "3× faster" folklore — and if that margin matters to you, measure it in your own service rather than inheriting it.
The other two shapes do not rescue the speed story either. Measuring them with a one-off script — TextBlob and Tiny are payload shapes this article invented for size comparison, and they are not in the published harness, so these two ratios are the least reproducible numbers here — protobufjs took 2.2× JSON.stringify's time on the string-dominated TextBlob and 1.4× on the numeric-dominated Tiny. The gap moves around by payload, but it never closes, and it is widest exactly where Protobuf's size advantage is weakest — 99.3% of JSON's bytes, and the slowest encode of the three.
This is a statement about protobufjs, not about Protocol Buffers. Native implementations in C++, Go, Java or Rust are a different story, and the official project's own positioning is about compactness and speed in those runtimes. If you are choosing a format for a Node.js service, benchmark your actual library — do not inherit a claim measured in C++.
The Order-shape timings and the byte counts in the size tables are rows of the dataset at /benchmarks — specifically the meta.serialization record written by the downloadable bench.mjs — so you can check the prose against the file instead of against me. Two full runs of that script produced byte counts identical to the byte, while the four timings moved between 7.6% and 29.5%. So treat the millisecond figures as indicative and the byte counts as exact, and re-run the script if you want your machine's own numbers.
5. proto3 presence and the JSON mapping
Two specification details cause most real-world Protobuf bugs, and both are worth knowing before you adopt it.
Presence is implicit by default. A proto3 scalar set to its zero value is not serialized, so the receiver cannot distinguish "unset" from "explicitly zero". The official guidance now recommends the explicit form:
"
optionalis recommended over implicit fields for maximum compatibility with Protobuf editions and proto2."
If status = 0 means PENDING in your enum, and a client omits the field, you cannot tell whether it meant PENDING or forgot to send it. Use optional when that distinction matters.
Two related rules from the same guide:
"In proto3, the first value defined in an enum definition must have the value zero and should have the name
ENUM_TYPE_NAME_UNSPECIFIEDorENUM_TYPE_NAME_UNKNOWN."
"Proto3 messages preserve unknown fields and include them during parsing and in the serialized output, which matches proto2 behavior."
That second one matters for forward compatibility: an old service reading a new message keeps the fields it does not understand and passes them through. (Note that some older tutorials claim proto3 discards unknown fields — the current documentation says the opposite.)
The JSON mapping is not plain JSON. If you use Protobuf's canonical JSON output, the rules differ from what JSON.stringify would produce:
| Type | Canonical Protobuf JSON |
|---|---|
int64 / uint64 / sint64 / fixed64 |
"JSON value will be a decimal string. Either numbers or strings are accepted." |
bytes |
"standard base64 encoding with paddings" |
enum |
"The name of the enum value as specified in proto is used." |
| field names | "Message field names are mapped to lowerCamelCase to be used as JSON object keys." |
null input |
"The field should remain unset, as though it was not present in the input at all." |
| unknown fields | "The Protobuf JSON parser should reject unknown fields by default but may provide an option to ignore unknown fields in parsing." |
Parsers accept both spellings: "Parsers accept both the lowerCamelCase name... and the original proto field name." And serializers "should not emit null values" — they omit unset fields instead.
I measured this too. The same 1,000 Order records serialize to 553,706 bytes as plain JSON but 544,101 bytes as canonical Protobuf JSON — smaller, because proto3 drops the zero-valued fields (gift: false, status: PENDING) that plain JSON keeps. So "Protobuf's JSON form" is a third format, not a synonym for JSON, and it is not byte-identical to what your frontend expects.
6. Choosing between them
| Your situation | Recommendation |
|---|---|
| Browser-facing REST API | JSON. Readability, native speed, zero schema distribution |
| Internal service-to-service, high volume, no compression | Protobuf. The 44.6% is real when you pay per byte |
| gRPC / Kafka / Redis payloads | Protobuf. Framing and schema evolution are built for it |
HTTP API with Content-Encoding: br |
JSON is competitive — measure before migrating |
| Mostly text (logs, articles, LLM output) | JSON. Protobuf saved 0.7% in my test |
| Config files humans edit | JSON or YAML. Protobuf is not self-describing |
| Node.js service, CPU-bound serialization | Benchmark first: protobufjs was slower than native JSON here |
| Mobile / embedded, battery and bandwidth constrained | Protobuf, and skip compression to save the CPU |
7. My reads
First, the size argument is usually made in the wrong unit. People compare raw bytes, then deploy behind a compressing proxy. My measurement says the advantage shrinks from 55.4% to −0.7% on the same data once Brotli is applied. Compare compressed bytes if compression is in your path, because that is what actually crosses the wire.
Second, "faster" is a claim about an implementation, not a format. The official documentation describes a compact binary encoding; it does not promise that a JavaScript varint loop beats V8's native JSON parser. On this machine protobufjs lost the encoding half by 1.6–1.9× and won the decoding half by only 1.1–1.3×. What survives a rerun is not "Protobuf is faster" — it is that a native C++ parser and a JavaScript one are different pieces of machinery, and the format label tells you nothing about which is in your process. Any comparison that omits the runtime and the library is incomplete.
Third, the real cost of Protobuf is organizational, not technical. You now have a .proto contract that must be versioned, distributed, and kept in sync across every consumer. JSON's schema lives in the payload. That is why Protobuf pays off inside a company with a build pipeline and hurts in a public API where every client is a stranger.
Fourth, string-dominated workloads should stop considering this migration. 99.3% is not a rounding error worth a schema rollout. If your payload is text, the format question is settled — spend the effort on compression instead: on the same Order JSON, gzip-6 produced 52,145 bytes and Brotli-11 produced 27,870, a 46.6% reduction that dwarfs anything the format switch bought you.
Fifth, and most useful: the two formats are not competitors at the same layer. Protobuf is a wire contract; JSON is a document format. The teams that get this right use Protobuf between services and JSON at the edge, and convert once. The teams that get it wrong pick one for everything and then fight the mismatch for years.
8. Try it in the browser
The JSON ↔ Protobuf tool on this site converts between JSON, Base64 and Protobuf binary. Upload one or more .proto files (imports are resolved automatically), paste JSON, and inspect the exact bytes — useful for confirming the varint and tag rules above against your own schema, and for checking what proto3 actually drops from your payload.
It handles both proto2 and proto3, which matters because the presence rules differ between them.
For the case where you have no .proto at all — what a raw decode can settle and what it can only guess — see Protobuf Without a Schema Is Guesswork.
References:
- Protocol Buffers encoding guide (varints, ZigZag, wire types, tags)
- Proto3 language guide (presence,
optional, enums, unknown fields) - Protobuf JSON mapping (int64, bytes, enums, field names, null)
- Protocol Buffers overview
- protobufjs (the JavaScript library used in the benchmark)
- Node.js zlib API (gzip and Brotli used for the compression comparison)
- RFC 1952: GZIP file format specification
- RFC 7932: Brotli Compressed Data Format
Benchmark environment: Node.js v24.22.0, Windows x64, protobufjs 8.8.0, 1,000 records per shape from a seeded LCG (seed 20261112), median of 15 timed rounds after 2 warmups. The Order-shape serialization numbers are the meta.serialization row of the published dataset at /benchmarks. Byte counts were identical across two independent runs; the four timings moved 7.6%–29.5% between them. Measured 2026-11-15.