---
title: addr.extract_bits
summary: null
url: >-
  https://www.fastly.com/documentation/reference/vcl/functions/addr/addr-extract-bits
---

```
INTEGER addr.extract_bits(IP ip, INTEGER start_bit, INTEGER bit_count)
```

**Available in:** all subroutines

Extracts `bit_count` bits (at most 32) starting with the bit number `start_bit`
from the given IPv4 or IPv6 address and return them in the form of a
non-negative integer.

Bit numbering starts at 0 from the right-most end of the address (the lowest 
order bit in the last byte of the address is bit number 0). As this function 
extracts bits from the address, it copies them to form the integer. In the 
address from which it extracts bits, the lowest order bit extracted from 
the first byte (the right-most byte) will be copied to the lowest order bit
in the resulting integer.

If this function goes past the highest order bit in the left-most byte in
the address before completing the copying of `bit_count` bits, then it will
leave the remaining high-order bits in the integer at zero.

The bit count can be, at most, 32. The start bit must be lower than 128. The
bit count plus start bit must be, at most, 128. If the VCL using this 
function violates any of these three constraints, then it will be rejected 
at compilation time. 

The start bit and bit count must be constant values.

IPv6 addresses are 128 bits long and IPv4 addresses are 32 bits long. This 
function behaves as if an IPv4 address were padded with zeros on the left 
to 128 bits. If this function is applied to an address that is neither IPv4
nor IPv6, then it will return 0.

## Example

```vcl
if (addr.extract_bits(server.ip, 0, 8) == 7) {
  /* received on an IPv4 address that ends in ".7" or an IPv6 address that ends in "07" */
}
```
