All Products
Search
Document Center

MaxCompute:NET_IP_NET_MASK

Last Updated:Mar 26, 2026

Generates an IPv4 or IPv6 network mask as a BINARY value based on a specified prefix length.

Syntax

BINARY NET_IP_NET_MASK(BIGINT <num_output_bytes>, BIGINT <prefix_length>)

Parameters

ParameterRequiredTypeDescription
num_output_bytesYesBIGINTNumber of bytes in the network mask. Set to 4 for IPv4 or 16 for IPv6.
prefix_lengthYesBIGINTNumber of leading bits set to 1 in the mask. Valid range: [0, num_output_bytes × 8]. For example, a prefix length of 24 in an IPv4 mask (/24) corresponds to 255.255.255.0.

Return value

Returns a BINARY value representing the network mask. To convert the result to a human-readable string, pass it to NET_IP_TO_STRING.

ConditionReturn value
NormalBINARY network mask
num_output_bytes or prefix_length is NULLNULL
num_output_bytes is not 4 or 16Error (NULL if odps.sql.udf.strict.mode is set to false)
prefix_length is negative or greater than 8 × num_output_bytesError (NULL if odps.sql.udf.strict.mode is set to false)

Examples

Basic examples

-- Returns =FF=FF=FF=00
SELECT NET_IP_NET_MASK(4, 24);

-- Returns =FF=FF=F0=00
SELECT NET_IP_NET_MASK(4, 20);

-- Returns =FF=FF=FF=FF
SELECT NET_IP_NET_MASK(4, 32);

-- Returns =00=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00
SELECT NET_IP_NET_MASK(16, 0);

-- Returns =80=00=00=00=00=00=00=00=00=00=00=00=00=00=00=00
SELECT NET_IP_NET_MASK(16, 1);

-- Returns =FF=FF=FF=FF=FF=FF=FF=FF=FF=FF=FF=FF=FF=FF=FF=FF
SELECT NET_IP_NET_MASK(16, 128);

-- Returns NULL
SELECT NET_IP_NET_MASK(NULL, 128);

-- Returns NULL
SELECT NET_IP_NET_MASK(4, NULL);

Convert to a readable format

Use NET_IP_NET_MASK with NET_IP_TO_STRING to get a human-readable network mask.

-- Returns 255.255.255.0
SELECT NET_IP_TO_STRING(NET_IP_NET_MASK(4, 24));

-- Returns ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff
SELECT NET_IP_TO_STRING(NET_IP_NET_MASK(16, 128));

-- Returns ffff:ffff:ffff:ffff::
SELECT NET_IP_TO_STRING(NET_IP_NET_MASK(16, 64));

Related functions

NET_IP_NET_MASK is a network function. For more information, see Network functions.