Protocol Buffers proto3 messages: field numbers, types, enums, defaults and reserved fields
Answer: Start the file with syntax = "proto3";, then define each message as typed fields, each with a unique field number. Never reuse a field number: when you delete a field, add its number (and name) to a reserved list.
Example
syntax = "proto3";
message SearchRequest {
reserved 5, 9 to 11;
reserved "old_field";
string query = 1;
int32 page_number = 2;
int32 results_per_page = 3;
Corpus corpus = 4;
repeated string tags = 6;
}
enum Corpus {
CORPUS_UNSPECIFIED = 0;
CORPUS_WEB = 1;
}
Field numbers
- Each field needs a number between 1 and 536,870,911, unique among all fields for that message.
- The Protobuf implementation reserves field numbers 19,000 to 19,999, and the compiler will complain if you use them.
- Numbers 1 through 15 take one byte to encode and 16 through 2047 take two bytes, so use 1 to 15 for the most-frequently-set fields.
- Reserved ranges are inclusive:
9 to 11is the same as9, 10, 11.
Syntax and labels
- The
editionorsyntaxline must be the first non-empty, non-comment line; with neither, the compiler assumes proto2. repeatedfields can appear zero or more times and keep their order; repeated scalar numeric fields use packed encoding by default in proto3.
Default values
When encoded bytes lack a field, reading it returns a type-specific default: the empty string for strings, empty bytes for bytes, false for bools, zero for numeric types, and the first defined enum value (which must be 0) for enums. Repeated and map fields default to empty. For message fields, the field is not set.
See also
Claims
- id: C1 claim: Field numbers 19,000 to 19,999 are reserved for the implementation. source: S2 evidence: "Field numbers
19,000to19,999are reserved for the Protobuf implementation."
- id: C2 claim: Field numbers 1 through 15 take one byte to encode. source: S2 evidence: "field numbers in the range 1 through 15 take one byte to encode"
- id: C3 claim: The enum default is the first defined value, which must be 0. source: S1 evidence: "which must be 0"
Sources
- [S1] Language Guide (proto 3). Protocol Buffers docs. https://protobuf.dev/programming-guides/proto3/ . License: BSD-3-Clause. Accessed 2026-11-18.
- [S2] proto3.md (source page). protocolbuffers/protocolbuffers.github.io (GitHub). https://github.com/protocolbuffers/protocolbuffers.github.io/blob/main/content/programming-guides/proto3.md . License: BSD-3-Clause. Accessed 2026-11-18.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Protocol Buffers docs, Language Guide (proto 3); protocolbuffers/protocolbuffers.github.io (GitHub), proto3.md (source page). BSD-3-Clause (https://raw.githubusercontent.com/protocolbuffers/protocolbuffers.github.io/main/LICENSE). Copyright Google Inc. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Protocol Buffers docs, Language Guide (proto 3); protocolbuffers/protocolbuffers.github.io (GitHub), proto3.md (source page). BSD-3-Clause (https://raw.githubusercontent.com/protocolbuffers/protocolbuffers.github.io/main/LICENSE). Copyright Google Inc.
Cite this
iinventedlight. 2026. "Protocol Buffers proto3 messages: field numbers, types, enums, defaults and reserved fields." iinventedlight Library, iil:note:qyejg4y7, version of 2026-11-18. https://iinventedlight.com/library/notes/protobuf-message-types/. License: CC-BY-4.0.
@misc{iil_note_qyejg4y7,
author = {{iinventedlight}},
title = {{Protocol Buffers proto3 messages: field numbers, types, enums, defaults and reserved fields}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-18},
url = {https://iinventedlight.com/library/notes/protobuf-message-types/},
note = {Permanent ID iil:note:qyejg4y7. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/protobuf-message-types.md.