# `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/dataprime/language-reference/functions-reference/index.md), **function** and **method** notation. These interchangeable forms allow flexibility in how you structure expressions.

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

```dataprime
(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

```json
{
    "ip_address": "154.67.8.42"
},
{
    "ip_address": "10.0.0.5"
}
```

### Example query

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

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

### Example output

```json
{
    "ip_address": "154.67.8.42"
}
```
