# rangeToCidr() function · @imqueue/net

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

Covers an address range with the fewest CIDR records that fit it exactly.

**Signature:**

```typescript
export declare function rangeToCidr(start: string, end: string, type?: NetworkType, canonical?: boolean): string[];
```

## Parameters


| Parameter | Type | Description |
| --- | --- | --- |
| start | string | first address in the range, inclusive |
| end | string | last address in the range, inclusive |
| type | [NetworkType](https://imqueue.org/api/net/latest/net.networktype/) | _(Optional)_ the family, if known; omit to have it detected from `start` |
| canonical | boolean | _(Optional)_ for IPv6, render expanded rather than compressed addresses |


**Returns:**

string\[\]

The records covering exactly `[start, end]`.

## Exceptions

TypeError if either address is invalid, or if `type` disagrees with `start`. Note that only `start` is checked against `type`, so a mismatched `end` is converted as whatever family `start` established.

## Default Value

`canonical` defaults to `false`

## Remarks

[intRangeToCidr()](https://imqueue.org/api/net/latest/net.intrangetocidr/) with both ends converted by [ipToInt()](https://imqueue.org/api/net/latest/net.iptoint/) first — the same minimal-cover behaviour, taking text instead of integers.

## Example


```typescript
rangeToCidr('10.0.0.0', '10.0.0.255');  // ['10.0.0.0/24']
rangeToCidr('10.0.0.1', '10.0.0.2');    // ['10.0.0.1/32', '10.0.0.2/32']
```

