The Library of Babel

A bijective universe of every possible 3,200-character page
40 lines × 80 characters · alphabet: a–z and space

Borges' Library

"The universe (which others call the Library) is composed of an indefinite, perhaps infinite number of hexagonal galleries..." — Jorge Luis Borges, The Library of Babel (1941)

Borges imagined a library containing every possible book of a fixed length: most volumes are gibberish, but somewhere on its shelves rest the true history of every person, the precise translation of every text, the record of your future, and the catalog of every other catalog. Every page that could be written, is written.

The Bijection

This library uses a 27-character alphabet (a–z plus space). A page is exactly 3,200 characters — treated as a single 3,200-digit number in base 27. That number is the page's coordinate. We unpack it into a hierarchical address (page, book, shelf, wall, then a remaining hex-id) for human readability, but the math is the same number.

coord → text: pack the address into one BigInt N; convert N to base 27, pad to 3,200 digits, map digits to letters. text → coord: invert exactly. Because the map is a bijection, every page has a unique address and every address has a unique page.

The total number of pages is 273200 — about 104,583 — astronomically larger than the number of atoms in the observable universe. Yet thanks to BigInt arithmetic in your browser, we can navigate to any page in milliseconds. Type a sentence in Search and watch the library locate the exact volume, shelf, and page that contains it.

Address Layout

Reading the address from least-significant to most-significant component:

  • page ∈ [1, 410] — one page within a book
  • book ∈ [1, 32] — one book on a shelf
  • shelf ∈ [1, 5] — one shelf on a wall
  • wall ∈ [1, 4] — one wall in a hexagonal gallery
  • hex-id — a base-36 identifier for the hexagon (potentially enormous)

Combined: N = hex_id · (4·5·32·410) + wall_idx · (5·32·410) + shelf_idx · (32·410) + book_idx · 410 + page_idx.