﻿---
title: ES|QL IP_PREFIX function
description: 
url: https://www.elastic.co/elastic/docs-builder/docs/2873/reference/query-languages/esql/functions-operators/ip-functions/ip_prefix
products:
  - Elasticsearch
---

# ES|QL IP_PREFIX function
## Syntax

![Embedded](https://www.elastic.co/elastic/docs-builder/docs/2873/reference/query-languages/esql/images/functions/ip_prefix.svg)


## Parameters

<definitions>
  <definition term="ip">
    IP address of type `ip` (both IPv4 and IPv6 are supported).
  </definition>
  <definition term="prefixLengthV4">
    Prefix length for IPv4 addresses.
  </definition>
  <definition term="prefixLengthV6">
    Prefix length for IPv6 addresses.
  </definition>
</definitions>


## Description

Truncates an IP to a given prefix length.

## Supported types


| ip  | prefixLengthV4 | prefixLengthV6 | result |
|-----|----------------|----------------|--------|
| ip  | integer        | integer        | ip     |


## Example

```esql
ROW ip4 = to_ip("1.2.3.4"), ip6 = TO_IP("fe80::cae2:65ff:fece:feb9")
| EVAL ip4_prefix = IP_PREFIX(ip4, 24, 0), ip6_prefix = IP_PREFIX(ip6, 0, 112);
```


| ip4:ip  | ip6:ip                      | ip4_prefix:ip | ip6_prefix:ip           |
|---------|-----------------------------|---------------|-------------------------|
| 1.2.3.4 | fe80::cae2:65ff:fece:feb9:: | 1.2.3.0       | fe80cae2:65ff:fece:0000 |