Skip to content

Converts an expression to a subnet value.

subnet(x:string|ip|subnet) -> subnet
subnet(x:string|ip|subnet, prefix:int) -> subnet

The subnet function converts an expression to a subnet.

The string expression to convert. The string can be a CIDR subnet such as "10.0.1.5/24" or a plain IP address such as "10.0.1.5".

Plain IPv4 addresses become /32 host subnets, and plain IPv6 addresses become /128 host subnets.

The IP address to convert. IPv4 addresses become /32 host subnets, and IPv6 addresses become /128 host subnets.

The subnet to return unchanged.

The CIDR prefix length for a plain IP address or subnet network address. IPv4 prefixes must be in the range 0 to 32, and IPv6 prefixes must be in the range 0 to 128.

Use prefix with plain IP values or existing subnet values. Strings that already contain CIDR notation return null when you also provide prefix.

from {x: subnet("1.2.3.4/16")}
{x: 1.2.0.0/16}
from {x: subnet(10.10.1.124, 24)}
{x: 10.10.1.0/24}

Convert a plain IP string to a host subnet

Section titled “Convert a plain IP string to a host subnet”
from {x: subnet("2001:db8::1")}
{x: 2001:db8::1/128}

Last updated: