# toBinaryList() function · @imqueue/net

Source: https://imqueue.org/api/net/latest/net.tobinarylist/
Published: 2026-08-01
Author: @imqueue maintainers (https://github.com/imqueue)
Package: @imqueue/net 3.0.2 — generated reference, not hand-written

Packs CIDR records into the sorted binary form that lookups binary-search over.

**Signature:**

```typescript
export declare function toBinaryList(networks: string[], type?: NetworkType): Buffer;
```

## Parameters


| Parameter | Type | Description |
| --- | --- | --- |
| networks | string\[\] | CIDR records, each needing an explicit `/prefix` |
| type | [NetworkType](https://imqueue.org/api/net/latest/net.networktype/) | _(Optional)_ the family, if known; omit to have it detected from the first record |


**Returns:**

Buffer

A buffer of `[start, end]` address pairs, little-endian, ascending by start address. Two addresses of [sizeOf()](https://imqueue.org/api/net/latest/net.sizeof/) bytes per record.

## Exceptions

TypeError if a record's address is invalid or belongs to another family than the first one.

RangeError if a record has no `/prefix` — see [cidrToRangeInt()](https://imqueue.org/api/net/latest/net.cidrtorangeint/).

## Remarks

Three things happen here that the caller can observe. Ranges are deduplicated, so two records covering the same range yield one entry — note that this compares ranges, not text, so `10.0.0.0/8` and `10.0.0.5/8` count as duplicates. They are then sorted, which is the precondition [NetworkList](https://imqueue.org/api/net/latest/net.networklist/) relies on for binary search. And the family is taken from `networks[0]`, so an empty array reaches [getType()](https://imqueue.org/api/net/latest/net.gettype/) as `undefined` and throws.

Overlapping ranges are kept as they are rather than merged, so a list can hold a network and a subnet of it. That costs a little space but never affects the answer.

