---
title: ip_network function
description: Learn the syntax of the ip\_network function of the SQL language in Databricks Runtime.
canonical_url: https://docs.databricks.com/gcp/en/sql/language-manual/functions/ip_network
---

# `ip_network` function

**Applies to:** ![check marked yes](https://docs.databricks.com/gcp/en/images/icons/check.png) Databricks Runtime 18.2 and above

Returns the network portion of an IPv4 or IPv6 CIDR block in its canonical form.

This function is aliased by [`ip_network_first` function](https://docs.databricks.com/gcp/en/sql/language-manual/functions/ip_network_first.md).

## Syntax

```
ip_network ( cidr )
```

## Arguments

* `cidr`: A `STRING` or `BINARY` value representing a valid IPv4 or IPv6 CIDR block.

## Returns

The same type as the input (`STRING` or `BINARY`), representing the canonical form of the network address.

The function returns `NULL` if the input is `NULL`.

## Error conditions

* If the input is not a valid CIDR block, the function returns [INVALID\_CIDR\_BLOCK](https://docs.databricks.com/gcp/en/error-messages/error-classes.md#invalid_cidr_block).

## Examples

```sql
> SELECT ip_network('192.168.1.100/24');
  192.168.1.0

> SELECT ip_network('10.32.1.5/16');
  10.32.0.0

> SELECT ip_network('2001:db8::1/32');
  2001:db8::

> SELECT ip_network('::ffff:192.0.2.128/120');
  ::ffff:192.0.2.0

> SELECT hex(ip_network(X'C0A8016418'));
  C0A80100

> SELECT ip_network(NULL);
  NULL

> SELECT ip_network('192.168.1.5');
  Error: INVALID_CIDR_BLOCK
```

## Related functions

* [`ip_network_first` function](https://docs.databricks.com/gcp/en/sql/language-manual/functions/ip_network_first.md)
* [`ip_network_last` function](https://docs.databricks.com/gcp/en/sql/language-manual/functions/ip_network_last.md)
* [`ip_prefix_length` function](https://docs.databricks.com/gcp/en/sql/language-manual/functions/ip_prefix_length.md)
