Random IPv4 Subnet Exercise Generator

Generate IPv4 address and prefix questions with computed network, broadcast, host-range, and capacity answers.

Description

Generate IPv4 subnet questions with calculated network, highest address, host range, and host capacity.

CIDR represents an IPv4 block with an address and a prefix length. The prefix fixes leading bits, leaving a power-of-two address span for the block.1

Each result.exercises item contains address, prefix, and answer. The answer has networkAddress, broadcastAddress, firstHost, lastHost, and totalHosts. These fields follow the repository’s CIDR calculator convention rather than verifying address availability.

For /31 point-to-point links the calculator treats both endpoints as hosts. A /32 represents one address; neither case subtracts two boundary positions.2

When to use Random IPv4 Subnet Exercise Generator

Use it for IPv4 mask and host-capacity exercises with an openly returned answer key.

How to use Random IPv4 Subnet Exercise Generator and understand its results

  1. Enter integer exerciseCount from 1 through 256 and ordered integer minimumPrefix and maximumPrefix from zero through 32.
  2. Run and show address with prefix as the question, retaining answer for checking.
  3. Compare networkAddress, the upper endpoint, and host range under the stated convention. Interpret totalHosts as host capacity, not always the raw number of address positions.
addressInteger = floor(randomDraw × 2^32); prefix = minimumPrefix + floor(randomDraw × (maximumPrefix − minimumPrefix + 1))

Two draws per exercise select a full 32-bit address and an inclusive prefix length.

block size = 2^(32 − prefix); totalHosts = block size − 2 for prefix ≤ 30, otherwise block size

The integer-to-IPv4 tool formats the address and the CIDR calculator masks network bits and derives endpoint fields.

For prefix at most 30, firstHost is networkAddress plus one and lastHost is the highest address minus one. For /31 and /32 the calculator returns the full span. broadcastAddress remains the upper-endpoint field name even in these special cases.

json
{
  "input": {
    "exerciseCount": 3,
    "minimumPrefix": 16,
    "maximumPrefix": 30
  },
  "randomDraw": 0.25,
  "output": {
    "result": {
      "exercises": [
        {
          "address": "64.0.0.0",
          "prefix": 19,
          "answer": {
            "broadcastAddress": "64.0.31.255",
            "firstHost": "64.0.0.1",
            "lastHost": "64.0.31.254",
            "networkAddress": "64.0.0.0",
            "totalHosts": 8190
          }
        },
        {
          "address": "64.0.0.0",
          "prefix": 19,
          "answer": {
            "broadcastAddress": "64.0.31.255",
            "firstHost": "64.0.0.1",
            "lastHost": "64.0.31.254",
            "networkAddress": "64.0.0.0",
            "totalHosts": 8190
          }
        },
        {
          "address": "64.0.0.0",
          "prefix": 19,
          "answer": {
            "broadcastAddress": "64.0.31.255",
            "firstHost": "64.0.0.1",
            "lastHost": "64.0.31.254",
            "networkAddress": "64.0.0.0",
            "totalHosts": 8190
          }
        }
      ]
    }
  }
}

Prefix zero spans all 2^32 positions, /31 has two hosts under the point-to-point convention, and /32 has one. Equal prefix bounds fix the mask but still consume its draw. Reversed bounds, counts above 256, and invalid draws fail.

Limitations and assumptions

The default source is Math.random; no seed input or cryptographic entropy guarantee is provided. Repeated runs may select the same result, and the distribution depends on the random source.

Addresses are sampled across the full IPv4 bit space, including reserved and special-purpose ranges. There is no private-address filter, routing, allocation, DNS, host-availability, or network-connectivity check.

Exercises can repeat and answers are included; learner interfaces must hide them separately. Calculator host capacity is not proof that every position can be assigned in a real deployment.

Alternative or Complementary methods

Calculate a subnet you choose with the deterministic CIDR tool. A host-set generator samples unique positions within one supplied block instead of drawing unrelated questions.

References

  1. RFC 4632: Classless Inter-domain Routing — IETF, RFC Editor

  2. RFC 3021: Using 31-Bit Prefixes on IPv4 Point-to-Point Links — IETF, RFC Editor

Similar or alternative tools

Don't forget to set a bookmark for tool.io!
Privacy | Imprint | Cookies