Copy as Markdown[Open in ChatGPT](https://chatgpt.com/?q=Read%20https%3A%2F%2Fcoralogix.com%2Fdocs%2Fdataprime%2Flanguage-reference%2Ffunctions-reference%2Fip%2Fipinsubnet.md%20and%20help%20me%20with%20my%20question%20about%20this%20Coralogix%20documentation%20page.)[Open in Claude](https://claude.ai/new?q=Read%20https%3A%2F%2Fcoralogix.com%2Fdocs%2Fdataprime%2Flanguage-reference%2Ffunctions-reference%2Fip%2Fipinsubnet.md%20and%20help%20me%20with%20my%20question%20about%20this%20Coralogix%20documentation%20page.)

# `ipInSubnet`

## Description

Return `true` if an IP address belongs to a given subnet, otherwise return `false`.

## Syntax

Like many functions in DataPrime, `ipInSubnet` supports<!-- --> [two notations](https://coralogix.com/docs/docs/dataprime/language-reference/functions-reference/.md),<!-- --> **function** and **method**. These interchangeable forms allow flexibility in how you structure expressions.

* Function notation
* Method notation

```
ipInSubnet(ip: string, ipPrefix: string): bool
```

```
(ip: string).ipInSubnet(ipPrefix: string): bool
```

## Arguments

| Name       | Type     | Required | Description                                           |
| ---------- | -------- | -------- | ----------------------------------------------------- |
| `ip`       | `string` | **true** | The IP address to test                                |
| `ipPrefix` | `string` | **true** | The CIDR range to check against, e.g. `154.67.8.0/24` |

## Example

**Use case: Filter documents by subnet membership**

Check if the field `ip_address` belongs to the subnet `154.67.8.0/24`. Documents with matching IPs are included in the result set, while others are excluded.

### Example data

```
{

    "ip_address": "154.67.8.42"

},

{

    "ip_address": "10.0.0.5"

}
```

### Example query

* Function notation
* Method notation

```
filter ipInSubnet(ip_address, '154.67.8.0/24')
```

```
filter ip_address.ipInSubnet('154.67.8.0/24')
```

### Example output

```
{

    "ip_address": "154.67.8.42"

}
```
