{
  "id": "ipv6-subnet",
  "version": "c14870e292f7",
  "status": "published",
  "name": "IPv6 Subnet Calculator",
  "question": "What is my IPv6 subnet range?",
  "summary": "Computes an IPv6 subnet from an address and a prefix length: the network, the first and last address, the number of addresses and of /64 subnets, the full and compressed address, and the address type.",
  "category": "logic",
  "subcategory": "networks",
  "url": "https://www.acalculator.org/logic/ipv6-subnet-calculator",
  "markdown": "https://www.acalculator.org/logic/ipv6-subnet-calculator.md",
  "kind": "function",
  "method": "network = address AND mask, last = network OR NOT mask, where the mask has prefix leading 1 bits of 128; addresses = 2^(128 − prefix).",
  "assumptions": [
    "The address may use any RFC 4291 text form: full, with leading zeros left out, with :: once, or with an IPv4 dotted quad as the last 32 bits.",
    "Results are written in the RFC 5952 form: lowercase hex, no leading zeros, :: for the longest run of two or more zero groups.",
    "IPv6 has no broadcast address, so every address from the first to the last is counted."
  ],
  "inputs": {
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "properties": {
      "ip": {
        "title": "IPv6 address",
        "description": "An IPv6 address such as 2001:db8::1, optionally with its prefix after a slash (2001:db8::1/48).",
        "type": "string",
        "maxLength": 49
      },
      "prefix": {
        "title": "Prefix length",
        "description": "How many leading bits are the network part (64 for a single LAN, 48 or 56 for a site).",
        "type": "string",
        "enum": [
          "0",
          "1",
          "2",
          "3",
          "4",
          "5",
          "6",
          "7",
          "8",
          "9",
          "10",
          "11",
          "12",
          "13",
          "14",
          "15",
          "16",
          "17",
          "18",
          "19",
          "20",
          "21",
          "22",
          "23",
          "24",
          "25",
          "26",
          "27",
          "28",
          "29",
          "30",
          "31",
          "32",
          "33",
          "34",
          "35",
          "36",
          "37",
          "38",
          "39",
          "40",
          "41",
          "42",
          "43",
          "44",
          "45",
          "46",
          "47",
          "48",
          "49",
          "50",
          "51",
          "52",
          "53",
          "54",
          "55",
          "56",
          "57",
          "58",
          "59",
          "60",
          "61",
          "62",
          "63",
          "64",
          "65",
          "66",
          "67",
          "68",
          "69",
          "70",
          "71",
          "72",
          "73",
          "74",
          "75",
          "76",
          "77",
          "78",
          "79",
          "80",
          "81",
          "82",
          "83",
          "84",
          "85",
          "86",
          "87",
          "88",
          "89",
          "90",
          "91",
          "92",
          "93",
          "94",
          "95",
          "96",
          "97",
          "98",
          "99",
          "100",
          "101",
          "102",
          "103",
          "104",
          "105",
          "106",
          "107",
          "108",
          "109",
          "110",
          "111",
          "112",
          "113",
          "114",
          "115",
          "116",
          "117",
          "118",
          "119",
          "120",
          "121",
          "122",
          "123",
          "124",
          "125",
          "126",
          "127",
          "128"
        ]
      }
    }
  },
  "outputs": {
    "cidr": {
      "label": "Network",
      "description": "The network address and prefix length.",
      "format": "text"
    },
    "range": {
      "label": "Address range",
      "description": "The first address (every host bit 0) and the last address (every host bit 1) of the subnet.",
      "format": "text"
    },
    "total": {
      "label": "Addresses",
      "description": "How many addresses the subnet holds: 2^(128 − prefix), written in full.",
      "format": "text"
    },
    "power": {
      "label": "Addresses as a power of 2",
      "description": "2^(128 − prefix).",
      "format": "text"
    },
    "subnets64": {
      "label": "/64 subnets",
      "description": "How many /64 subnets fit in the prefix: 2^(64 − prefix), for prefixes up to /64.",
      "format": "text"
    },
    "network": {
      "label": "Network address",
      "description": "The address with every host bit 0, compressed.",
      "format": "text"
    },
    "last": {
      "label": "Last address",
      "description": "The address with every host bit 1, compressed.",
      "format": "text"
    },
    "expanded": {
      "label": "Full address",
      "description": "The address typed, with all eight groups written as four hex digits.",
      "format": "text"
    },
    "compressed": {
      "label": "Compressed address",
      "description": "The address typed, in the RFC 5952 short form.",
      "format": "text"
    },
    "addressType": {
      "label": "Address type",
      "description": "The block of the IPv6 address space the address is in.",
      "format": "text"
    }
  },
  "defaultAnswer": {
    "inputs": {
      "ip": "2001:db8:abcd:12::1",
      "prefix": "64"
    },
    "outputs": {
      "cidr": "2001:db8:abcd:12::/64",
      "range": "2001:db8:abcd:12:: – 2001:db8:abcd:12:ffff:ffff:ffff:ffff",
      "total": "18,446,744,073,709,551,616",
      "power": "2^64",
      "subnets64": "1",
      "network": "2001:db8:abcd:12::",
      "last": "2001:db8:abcd:12:ffff:ffff:ffff:ffff",
      "expanded": "2001:0db8:abcd:0012:0000:0000:0000:0001",
      "compressed": "2001:db8:abcd:12::1",
      "addressType": "Documentation"
    },
    "text": "The subnet 2001:db8:abcd:12::/64 holds 18,446,744,073,709,551,616 addresses (2001:db8:abcd:12:: – 2001:db8:abcd:12:ffff:ffff:ffff:ffff)."
  },
  "examples": [
    {
      "given": {
        "ip": "2001:db8:abcd:12::1",
        "prefix": "64"
      },
      "expect": {
        "cidr": "2001:db8:abcd:12::/64",
        "range": "2001:db8:abcd:12:: – 2001:db8:abcd:12:ffff:ffff:ffff:ffff",
        "total": "18,446,744,073,709,551,616",
        "power": "2^64",
        "subnets64": "1",
        "expanded": "2001:0db8:abcd:0012:0000:0000:0000:0001",
        "compressed": "2001:db8:abcd:12::1",
        "addressType": "Documentation"
      },
      "source": "hand calculation in content.mdx; Python 3 ipaddress.ip_network('2001:db8:abcd:12::1/64', strict=False); RFC 4291, IP Version 6 Addressing Architecture, section 2.2 and 2.3. https://www.rfc-editor.org/rfc/rfc4291; RFC 5952, A Recommendation for IPv6 Address Text Representation, section 4. https://www.rfc-editor.org/rfc/rfc5952; RFC 3849 (2001:db8::/32 documentation prefix), https://www.rfc-editor.org/rfc/rfc3849"
    },
    {
      "given": {
        "ip": "2001:0DB8:0000:0000:0001:0000:0000:0001/48"
      },
      "expect": {
        "cidr": "2001:db8::/48",
        "last": "2001:db8:0:ffff:ffff:ffff:ffff:ffff",
        "total": "1,208,925,819,614,629,174,706,176",
        "subnets64": "65,536",
        "compressed": "2001:db8::1:0:0:1"
      },
      "source": "RFC 5952, A Recommendation for IPv6 Address Text Representation, section 4. https://www.rfc-editor.org/rfc/rfc5952 (example 2001:db8::1:0:0:1: the first of two equal runs of zeros is compressed); 2^80 = 1,208,925,819,614,629,174,706,176; Python 3 ipaddress"
    },
    {
      "given": {
        "ip": "fe80::1ff:fe23:4567:890a",
        "prefix": "10"
      },
      "expect": {
        "cidr": "fe80::/10",
        "last": "febf:ffff:ffff:ffff:ffff:ffff:ffff:ffff",
        "addressType": "Link-local unicast"
      },
      "source": "RFC 4291, IP Version 6 Addressing Architecture, section 2.2 and 2.3. https://www.rfc-editor.org/rfc/rfc4291 (section 2.5.6: link-local unicast is FE80::/10); Python 3 ipaddress"
    },
    {
      "given": {
        "ip": "2001:db8:0:1:1:1:1:1",
        "prefix": "128"
      },
      "expect": {
        "cidr": "2001:db8:0:1:1:1:1:1/128",
        "range": "2001:db8:0:1:1:1:1:1",
        "total": "1",
        "compressed": "2001:db8:0:1:1:1:1:1"
      },
      "source": "RFC 5952, A Recommendation for IPv6 Address Text Representation, section 4. https://www.rfc-editor.org/rfc/rfc5952 (section 4.2.2: :: must not shorten one 16-bit 0 field; 4.2.3: the longest run is shortened); Python 3 ipaddress"
    },
    {
      "given": {
        "ip": "::ffff:192.0.2.128/96"
      },
      "expect": {
        "cidr": "::ffff:0:0/96",
        "expanded": "0000:0000:0000:0000:0000:ffff:c000:0280",
        "total": "4,294,967,296"
      },
      "source": "RFC 4291, IP Version 6 Addressing Architecture, section 2.2 and 2.3. https://www.rfc-editor.org/rfc/rfc4291 (section 2.2 form 3 and 2.5.5.2, IPv4-mapped ::ffff:0:0/96); 192 = c0, 0 = 00, 2 = 02, 128 = 80; Python 3 ipaddress"
    }
  ],
  "sources": [
    "RFC 4291, IP Version 6 Addressing Architecture (text forms in section 2.2, prefixes in 2.3, special addresses in 2.5 and 2.7). https://www.rfc-editor.org/rfc/rfc4291 (retrieved 2026-10-19)",
    "RFC 5952, A Recommendation for IPv6 Address Text Representation (section 4). https://www.rfc-editor.org/rfc/rfc5952 (retrieved 2026-10-19)",
    "RFC 4193, Unique Local IPv6 Unicast Addresses (fc00::/7). https://www.rfc-editor.org/rfc/rfc4193 (retrieved 2026-10-19)",
    "RFC 3849, IPv6 Address Prefix Reserved for Documentation (2001:db8::/32). https://www.rfc-editor.org/rfc/rfc3849 (retrieved 2026-10-19)"
  ],
  "related": [
    "subnet"
  ],
  "changelog": []
}
