intRangeToCidr() function

Covers an integer address range with the fewest CIDR records that fit it exactly.

Signature:

export declare function intRangeToCidr(start: bigint, end: bigint, type: NetworkType, canonical?: boolean): string[];

Parameters

Parameter

Type

Description

start

bigint

first address in the range, inclusive

end

bigint

last address in the range, inclusive

type

NetworkType

which family the two integers belong to

canonical

boolean

(Optional) for IPv6, render expanded rather than compressed addresses

Returns:

string[]

The records covering exactly [start, end] — no more and no less.

Default Value

canonical defaults to false

Remarks

The inverse of cidrToRangeInt(), and not a one-to-one one: an arbitrary range rarely aligns to a single prefix, so this splits it into the minimal set that does. A range already on a prefix boundary comes back as one record.

type is required here and cannot be inferred, for the same reason as in intToIp() — the integers alone do not say which family they are. The range is not validated, so an end below start yields an empty list rather than an error.

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