← All notes

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

Sources

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

Permanent ID: iil:note:my4ws2gx

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.},
}

Markdown

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.

All artifact files (JSON index)

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.