My book, The Library: A Catalogue of Wonders, began as an essay on writers’ libraries but quickly grew to encompass public and fictional ones as well. Ancient, modern and imaginary libraries have all accumulated compelling and irresistible stories.

Mysterious filaments connect fictional libraries to each other, and to real libraries. Here are my favourites.

1. The Hobbit by JRR Tolkien

Tolkien’s works are set in an exquisitely realised fantasy world that features grand libraries, such as those of Minas Tirith and Rivendell, but also humble ones, such as those of the Shire. The best Shire libraries are at Undertowers, Great Smials, Brandy Hall and Bag End, an English country house in miniature and underground. Bag End has everything a civilised Hobbit could ever need: panelled walls, a tiled floor, fireplace, fine furniture and low bookshelves – because Hobbits don’t like ladders. The Lord of the Rings features accurate descriptions of tablets, scrolls, codices and even the bindings of fabled Shire books such as the Red Book of Westmarch, and the Yearbook of Tuckborough, known as Yellowskin.

2. The Catalogue of Rare Books Not for Sale by John Donne

When Paul Masson noticed that the Bibliothèque Nationale had few Latin and Italian books from the 15th century, he decided to fabricate a list of volumes that would enhance the catalogue. What, Colette asked, was the use of books that did not exist? “Well,” Masson answered indignantly, “I can’t be expected to think of everything!” Sometime between 1603 and 1611, Donne produced this similarly fanciful booklist. Its imaginary titles – such as Hoby’s Afternoon Belchings and Luther’s On Shortening the Lord’s Prayer – aimed to impart pseudo-wisdom to courtiers. Also in this tradition of imaginary booklists is the catalogue compiled by Rabelais that includes The Codpiece of the Law, The Testes of Theology and Martingale Breeches with Back-flaps for Turd-droppers.

3. Tik-Tok by John Sladek

This 1983 novel is about a cynical robot that becomes vice president of the US. Sladek imagines a vast, interplanetary mobile library aboard the Liberian-registered Doodlebug, a luxurious spaceship for interplanetary tourists. After an economic slump, the ship is repurposed to transport livestock. Tik-Tok frequents the silent ballroom, the deluxe bathrooms and the first-class library, which he consults by category: books about Mars; autobiographies of former nuns; books that feature a robot named Robbie; books whose titles begin with “U” and which conceal “profane meanings”.

A long way from Babel … Jorge Luis Borges at home in Buenos Aires in 1983. Photograph: Christopher Pillitz/Getty Images

4. The Library of Babel by Jorge Luis Borges

In 1938, Borges banged his head and entered a speechless delirium. His mother revived him by reading aloud from CS Lewis. Soon after, Borges conceived this vision of an infinite library composed of interconnected hexagonal rooms, all identical and containing standardised bookshelves and randomised books. In this infinite repository, most texts are gibberish but many are not. The library contains every book ever written, as well as every book that might be. Sought after titles include: “Everything: the minutely detailed history of the future, the archangels’ autobiographies, the faithful catalogues of the Library, thousands and thousands of false catalogues, the demonstration of the fallacy of those catalogues, the demonstration of the fallacy of the true catalogue, the Gnostic gospel of Basilides, the commentary on that gospel, the commentary on the commentary on that gospel, the true story of your death, the translation of every book in all languages … ”

5. The Name of the Rose by Umberto Eco

In a Benedictine monastery, Eco had an epiphany that led him to create the most captivating library in fiction: the abbey library in this international bestseller. When constructing the collection, Eco had in mind Borges’s labyrinth. As finally conceived, it features hexagonal rooms and a librarian, “Jorge da Burgos”. Perhaps oddly, Eco’s book rooms are less historically accurate than Tolkien’s. The chief libraries of medieval Europe held fewer than 2,000 volumes. Eco’s abbey library of an impossible 87,000 books drew criticism from mediaevalists. But, as Lucien Polastron noted, “Dream and fantasy laugh at accountants.”

6. The Cemetery of Lost Books in The Shadow of the Wind by Carlos Ruiz Zafón

In Zafón’s baroque novel, Daniel Sempere hides a volume in this secret collection, itself hidden in the heart of old Barcelona. Zafón took inspiration from galleries of mirrors; stories within stories; the multi-level bookshop of Francis Edwards in Hay-on-Wye; the multi-room London bookshop of Wilfrid Voynich, said to have been organised in a deliberate sequence of crammed spaces so as to enhance the sense of drama and discovery; Eco’s abbey library; and the dépôts littéraires of revolutionary France, in which looted books were amassed on a brutal scale.

7. The Citadel Library in A Song of Ice and Fire by George RR Martin

In the bestselling fantasy series, the Citadel at Oldtown features a great library – the largest of its kind in Westeros – that is a medieval marvel. As realised in Game of Thrones on TV, the library features a vast central hall in which a suspended structure of lenses and mirrors diffuses natural light. The library’s most valuable and dangerous books are stored behind locked gates, and are chained to the shelves, just as they are at Unseen University on Discworld and in the cathedral library of Hereford.

8. Peter Kien’s books in Auto-da-Fé by Elias Canetti

Peter Kien, a middle-aged Sinologist, assembles some 25,000 volumes in his Vienna apartment. His insatiable appetite for books is matched only by the fear that they will be lost in fire. He marries his sturdy housekeeper with the idea that she will help keep the books safe. Instead, she forces him out of his apartment and he enters a nightmarish world of cutthroats, con artists, seedy bars and bungling police. The book ends with a powerful depiction of the horror of burning books.

9. Night Lamp by Jack Vance

In the abandoned palace of Somar, the characters Jaro and Skirl find a library crowded with ancient illustrated books that smell pleasantly of wax and preservative. Part diary, part poem, each book is a repository of a unique artistic vision that allows the author to live for ever in a half-dream within the lovingly created pages. Behind the library walls are passages that lead to safe houses and the homes of ghouls.

Unpredictable opening hours … The Night Bookmobile. Photograph: Audrey Niffenegger

10. The Night Bookmobile by Audrey Niffenegger

Another fantastical treatment of books and death. A young woman encounters a mobile library, a kind of Winnebago–Tardis, that contains every book she has ever read or skimmed. The librarian, Mr Openshaw, carefully curates the collection. The woman searches but doesn’t see it for another nine years. When she meets Openshaw again, she begs to become his assistant. He refuses but she studies librarianship and goes to work at the Chicago Public Library. Twelve years on, she is reunited with Openshaw and the Bookmobile, but he again refuses to hire her before the decisive event I won’t spoil.

• The Library: A Catalogue of Wonders by Stuart Kells is published by Text.

