> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://rivet.chrisboulton.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://rivet.chrisboulton.com/_mcp/server.

# IP network functions

> Signatures, behavior, examples, and Rivet compatibility boundaries.

CIDR functions normalize IPv4 or IPv6 network prefixes. Host/subnet indices are signed 64-bit integer arguments.

| Function                              | Result and rules                                                                                                         |
| ------------------------------------- | ------------------------------------------------------------------------------------------------------------------------ |
| `cidrhost(prefix, host)`              | Address at host offset; negative offsets count backward from the last address.                                           |
| `cidrnetmask(prefix)`                 | IPv4 netmask; IPv6 is rejected.                                                                                          |
| `cidrsubnet(prefix, newbits, number)` | One subnet obtained by extending the prefix by newbits and selecting a nonnegative subnet number.                        |
| `cidrsubnets(prefix, newbits...)`     | Sequential, naturally aligned subnets for each extension; each newbits is positive, at most 32, and must fit the prefix. |

Out-of-range indices, invalid prefixes, impossible extensions, and exhausted address space fail. No host discovery, DNS resolution, or network request occurs.

## Example

```hcl
locals {
  network = {
    host = cidrhost("192.0.2.0/24", 10)
    mask = cidrnetmask("192.0.2.0/24")
    subnet = cidrsubnet("192.0.2.0/24", 2, 1)
    subnets = cidrsubnets("192.0.2.0/24", 2, 2)
  }
}
output "network" {
  type  = string
  value = jsonencode(local.network)
}
```

All calls obey the [function limits and annotation rules](/language/functions).