cidrToRangeInt() function

Expands a CIDR record into the first and last address it covers, as integers.

Signature:

export declare function cidrToRangeInt(cidr: string, type?: NetworkType): [bigint, bigint];

Parameters

Parameter

Type

Description

cidr

string

a network in address/prefix form, e.g. 10.0.0.0/8

type

NetworkType

(Optional) the family, if known; omit to have it detected from cidr

Returns:

[bigint, bigint]

A [first, last] tuple. Both ends are inclusive, so a /32 returns the same value twice.

Exceptions

TypeError if the address part is invalid or disagrees with type.

RangeError if there is no /prefix. A bare 10.0.0.1 makes the prefix undefined, which reaches BigInt(NaN) — so the failure surfaces as Cannot convert NaN to a BigInt rather than as a message about the record. This is why every network given to Networks needs an explicit prefix length, /32 and /128 included.

Remarks

Host bits in the address are cleared rather than rejected, so 10.0.0.5/8 is accepted and yields the same range as 10.0.0.0/8. The prefix itself is not bounds-checked: a value above the family width produces a negative shift and throws from BigInt, and a negative one produces a nonsensical range.

Read this page as plain markdown — no HTML, no navigation. For pasting into an LLM, or for an agent to fetch.