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

# `ip_prefix_length` function

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

Returns the prefix length of an IPv4 or IPv6 CIDR block.

## Syntax

```
ip_prefix_length ( cidr )
```

## Arguments

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

## Returns

An `INTEGER` representing the prefix length of 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/gcp/en/error-messages/error-classes.md#invalid_cidr_block).

## Examples

```sql
> SELECT ip_prefix_length('192.168.1.1/24');
  24

> SELECT ip_prefix_length('2001:db8::1/64');
  64

> SELECT ip_prefix_length('::ffff:192.0.2.1/96');
  96

> SELECT ip_prefix_length(X'C0A8010118');
  24

> SELECT ip_prefix_length(NULL);
  NULL

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

## Related functions

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