In 18th-century Venice, as the canals turned fetid, the heirs to the tradition of Carpaccio and Gentile Bellini settled for selling pictures of the Rialto bridge to tourists. But Canaletto, Bellotto and the Guardi brothers, the painters who catered for this market, liked to take time off to let fancy fly, to imagine other cities and fantastic versions of their own.

As he drew the silhouettes against the vast machinery, suspending them, haggard, bent in a direction that was not a direction, for the stairs and bridges, the future extends as far as one can see, as far as one can stand it. Giovanni Battista Piranesi’s series of etchings of imaginary prisons, Le Carceri, is not often thought of in terms of Venetian view painting, for good reason.

He was a draughts man and print maker, his most famous views are of the ruins of ancient Rome, and while Canaletto is stuck in a realm of greeting-card elegance, Piranesi is a fiercely living artist, a spectacular influence on modern culture. And yet he was a Venetian, and it is in the decadent, pessimistic fancies of a doomed city that we may find the true source of his macabre ecstasy.

Ever since they were published — the first edition in the late 1740s, the second, even darker one in 1761 — Piranesi’s monstrous images of prisons as cruelly proliferating mega-cities have inspired designers, writers and architects. As early as 1760 a spectacular set for Rameau’s opera Dardanus copied one of Piranesi’s boundless prison spaces. It was the beginning of a darkly glittering stage and film career for Piranesi’s images, from Metropolis and Blade Runner to the moving staircases at Hogwarts. In today’s architecture, you see Piranesi’s imagination in Tate Modern, and London Underground’s Jubilee line.

And yet Piranesi was a view artist — indeed, that was all he was, he would have said, because his unfulfilled ambition was to be an architect. Born in Venice, he got away from the place as soon as he could, but could never leave its pervasive air of decline. He did not find modernity, or progress, or the Enlightenment. His addiction to the ruins of Rome, his intoxication with their immensity, their power, seems pathological. The chance to see Le Carceri is a chance to look beyond their mythic charisma to find Piranesi himself inside his imaginary spaces.

Just like Canaletto’s paintings, Piranesi’s prints were conceived as souvenirs – that is what Italy had come to by the 18th century. The first edition of the ‘Carceri’ was not even published in his name; instead the frontispiece names the publisher, giving the address of his shop in Rome. When Piranesi republished the series in the extrasinister edition of 1761, this time announcing them for sale at his own address near the Spanish Steps, he gave himself an opening credit as “G Battista Piranesi, Venetian architect”. This was as much a fantasy as the prisons themselves.

He did build one church in Rome, Santa Maria del Priorato, and he published books of architectural history and theory. But Piranesi’s chief contribution to practical — as against imaginary — design was to fabricate what an ungenerous critic would call fakes. Piranesi sold “antiques”: that is, he put together bits of ancient Roman sculpture that he and others had dug up — a carving of a lion’s foot, a couple of fauns’ heads —to fabricate imposing, profuse objects you can imagine gracing Nero’s palace. Today, museums do not know quite what to do with these oddities.

What was it, after all, to be a “Venetian architect” in the 18th century? The chances of creating something new seemed remote in a country that was already an architectural museum. The place was well on its way to becoming a ghost upon the sands of the sea, as John Ruskin described it in 1851. A story about another famous contemporary Venetian suggests the reality behind Piranesi’s fantasia, conceived when he was only in his 20s. In 1755 Casanova was arrested by the Inquisition for crimes ranging from blasphemy to encouraging Venetian aristocrats to become freemasons. His sexual relationship with a nun did not help. He was taken from his home to the doge’s palace and, without a trial, dumped in a small cell in the building, which can still be visited today. The ceiling is about five feet high.

Eighteenth-century artists, writers and radicals routinely compared the social order to a prison. It seemed as if the boundary between the deathly other world of prison and the illuminated outside world was very thin, as if one could slip constantly between the two.

It was only in the second edition of his Carceri that Piranesi sited his prisons in ancient Rome. Perhaps he wanted to cash in on what by now was an international reputation as a student of Rome. Or perhaps he wanted to cover the subversive possibility that these prisons are dream images of his own time, his own society.

Piranesi is more than half in love with his prisons. They are a place his imagination can wander, and at the same time an impossible place— the prints contain spatial paradoxes, including a staircase that exists on two planes simultaneously. It is a place without limits or contexts: Piranesi’s prison interiors have no outer walls, and each vista is cut off only by the frame of the image itself. There are views through arches of almost recognisable Roman sights— the colonnade of St Peter’s. But there is nothing to tell us that these mark terminal points of the prison. Instead, they are incorporated into it.

While prisoners undergo mysterious torments, luckier souls pass by on parapets or bridges that have no logic or necessity. Piranesi argued that architecture should indulge in grotesque ornament; the architecture of his prisons is redundant, it is not functional, it relishes itself.

There is a perverse freedom to this that makes it easy to understand why Edgar Allan Poe was a fan — Poe’s story The Pit and the Pendulum is a transcription of the world of Piranesi’s Carceri. A wheel with spikes around its circumference; a post with more spikes; a kind of chandelier suspended from a beam, which on closer inspection looks like it might be ringed with meat-hooks; pulleys, one of which raises and lowers a basket big enough to contain a person into a huge marble vat. And yet, in most of the pictures, we do not actually see anyone being tortured. It is all suggested rather than shown. A couple of prison guards — or they might be prisoners doing forced labour — dig a grave in the middle of the prison. Elsewhere, there are glimpses of the damned.

A man being pulled on a rack. Naked figures chained to posts while high above them it looks as if a musician is playing the fiddle. Higher still, spectators gather on a vertiginous walkway. It is impossible to tell at times who is a prisoner, who a guard, who a visitor. In the end you suspect that everyone in this place is a prisoner. At the same time, they might all be here by some perverse choice —there is a languid quality to it all; the tortures and chaining are relaxed, almost consensual.

Can there be peace behind bars? Can there really be this enormous sigh of a void of contemplation that is as long as a lifetime of memory of blue skies that pass at dawn or dusk, and as slow as the recitative of a passing cloud, hiding behind prison bars? Through Piranesi’s keyhole of self-confinement ancient and modern confinements of time and space became apparent.

What his etchings demand is a dateless “bear with me”. Bearing and biding, for nothing, for all time, is truly monstrous. The monstrous is often a set of photographic negatives hanging upside down in an infernal “dark room” deep inside the cortex of Piranesi’s imagination. Well, he would have been a failed photographer too, only one ahead of his times. That is how the shadow of Cacerigrows upon us.

Piranesi clearly saw himself as a failure, dreamed incessantly of becoming what he said he was, a “Venetian architect”, while being more and more successful in his production of tourist art of genius.

After weeks of preparation and one foiled attempt, Casanova broke out of his cell one night in the doge’s palace, made his way along the rooftop until he found a way to the other parts of the palace; after tiptoeing through its chambers he walked cockily past a night-watchman and got a gondola out of the city. Casanova escaped. But looking at Le Carceri, it does not seem that Piranesi either believed it was possible to escape from the prison he was enclosed in, which was without walls and without an exterior; he was one of the damned. Piranesi seems to have succumbed to the ultimate corruption: taking pleasure in his punishment.