Go net/netip: a small comparable IP address type
Answer: Package netip defines an IP address type that's a small value type.
Addr, AddrPort, and Prefix
The Addr type is a small value type.
AddrPort combines an IP address and a port.
Prefix combines an IP address and a bit length prefix.
Why Addr differs from net IP
Compared with the older net IP type, Addr takes less memory.
Addr is also immutable and comparable, so it can be a map key.
The zero Addr is not a valid IP address.
See also
Claims
- id: C1 claim: The package defines a small value type for IP addresses. source: S1 evidence: "an IP address type that's a small value type"
- id: C2 claim: AddrPort pairs an address with a port. source: S1 evidence: "AddrPort (an IP address and a port)"
- id: C3 claim: Addr takes less memory and is immutable. source: S2 evidence: "takes less memory, is immutable,"
- id: C4 claim: The zero Addr is not a valid IP address. source: S2 evidence: "The zero Addr is not a valid IP address."
Sources
- [S1] net/netip package reference. Go. https://pkg.go.dev/net/netip . License: BSD-3-Clause. Accessed 2026-11-23.
- [S2] net/netip source. Go. https://go.dev/src/net/netip/netip.go . License: BSD-3-Clause. Accessed 2026-11-23.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: Go, net/netip package reference; Go, net/netip source. BSD-3-Clause (https://go.dev/LICENSE). Copyright The Go Authors. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: Go, net/netip package reference; Go, net/netip source. BSD-3-Clause (https://go.dev/LICENSE). Copyright The Go Authors.
Cite this
iinventedlight. 2026. "Go net/netip: a small comparable IP address type." iinventedlight Library, iil:note:my4ws2gx, version of 2026-11-23. https://iinventedlight.com/library/notes/go-net-netip/. License: CC-BY-4.0.
@misc{iil_note_my4ws2gx,
author = {{iinventedlight}},
title = {{Go net/netip: a small comparable IP address type}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-23},
url = {https://iinventedlight.com/library/notes/go-net-netip/},
note = {Permanent ID iil:note:my4ws2gx. 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).
Extra files beside this note
These files use this note's license, shown below. Paper extras retain their reproduction status; a link is not a reproduction.
- go-net-netip.schema.json (schema; CC-BY-4.0)
- go-net-netip.table.json (table; CC-BY-4.0)
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/go-net-netip.md.