---
title: ip_network_first
description: "ip\\_network\\_first function in PySpark: Returns the network portion of an IPv4 or IPv6 CIDR block in its canonical form."
canonical_url: https://docs.databricks.com/gcp/en/pyspark/reference/functions/ip_network_first
---

# ip\_network\_first

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

> [!NOTE]
> **Beta**
>
> This feature is in [Beta](https://docs.databricks.com/gcp/en/release-notes/release-types.md).

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

This function is an alias for [ip\_network](https://docs.databricks.com/gcp/en/pyspark/reference/functions/ip_network.md).

For the corresponding SQL function, see [`ip_network_first` function](https://docs.databricks.com/gcp/en/sql/language-manual/functions/ip_network_first.md).

## Syntax

```python
from pyspark.databricks.sql import functions as dbf

dbf.ip_network_first(col=<col>)
```

## Parameters

| Parameter | Type                          | Description                                                            |
| --------- | ----------------------------- | ---------------------------------------------------------------------- |
| `col`     | `pyspark.sql.Column` or `str` | A STRING or BINARY value representing a valid IPv4 or IPv6 CIDR block. |

## Examples

**Example 1**: Get first address from an IPv4 CIDR block.

```python
from pyspark.databricks.sql import functions as dbf
df = spark.createDataFrame([('192.168.1.5/24',)], ['cidr'])
df.select(dbf.ip_network_first('cidr').alias('result')).collect()
```

```Output
[Row(result='192.168.1.0')]
```

**Example 2**: Get first address from an IPv6 CIDR block.

```python
from pyspark.databricks.sql import functions as dbf
df = spark.createDataFrame([('2001:db8::1/32',)], ['cidr'])
df.select(dbf.ip_network_first('cidr').alias('result')).collect()
```

```Output
[Row(result='2001:db8::')]
```

**Example 3**: `None` input returns `None`.

```python
from pyspark.databricks.sql import functions as dbf
df = spark.createDataFrame([(None,)], 'cidr: string')
df.select(dbf.ip_network_first('cidr').alias('result')).collect()
```

```Output
[Row(result=None)]
```
