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

# `ip_network_last` function

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

Returns the last address of an IPv4 or IPv6 CIDR block in its canonical form.

## Syntax

```
ip_network_last ( 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 last address in the CIDR block.

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/aws/en/error-messages/error-classes.md#invalid_cidr_block).

## Examples

```sql
> SELECT ip_network_last('192.168.1.0/24');
  192.168.1.255

> SELECT ip_network_last('2001:db8::/32');
  2001:db8:ffff:ffff:ffff:ffff:ffff:ffff

> SELECT ip_network_last('::ffff:192.0.2.0/120');
  ::ffff:192.0.2.255

> SELECT hex(ip_network_last(X'C0A8016418'));
  C0A801FF

> SELECT ip_network_last(NULL);
  NULL

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

## Related functions

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