The wall around the home of the gods was built by a contractor they never intended to pay.
Gylfaginning tells it as a story about a bad contract. A builder arrives offering to construct a fortification so strong that no giant can get in, in three seasons, for a fee of the sun, the moon and Freyja. The gods counter-offer on Loki's advice: one winter, no help from any man, and if any part is unfinished on the first day of summer he gets nothing. The builder asks to use his horse. Loki says yes.
The horse, Svaðilfæri, hauls stone at a rate nobody anticipated, and three days before the deadline the wall is all but done. The gods, facing the loss of the sky and the goddess, hold a meeting and conclude that Loki got them into this and Loki will get them out on pain of death. He goes out that night as a mare, the stallion breaks its traces and follows, no work is done, the builder loses his temper and reveals himself as a giant, and Thor — who had been away in the east — kills him with the hammer.
Loki, some time afterwards, gives birth to Sleipnir.
Snorri closes the episode by noting that the gods had sworn oaths to guarantee the builder's safety, and broke them. This is the foundation story of Ásgarðr: the stronghold of the gods is built on a fraudulent tender, an oath violated, and a stallion's distraction.
What is inside it
Grímnismál lists twelve or thirteen dwellings without describing a city: Þrúðheimr, Ýdalir and Álfheimr, Valaskjálf with its silver roof, Sökkvabekkr where Odin and Sága drink from golden cups, Glaðsheimr and Valhalla, Þrymheimr, Breiðablik, Himinbjörg, Fólkvangr, Glitnir, Nóatún and Landvíði.
The list is a problem for anyone drawing a map. Þrymheimr is in the mountains of the giants. Nóatún is on the shore. Álfheimr belongs to the elves. These are not districts of one settlement; they are the halls of individual gods scattered across a landscape, gathered into a poem by association rather than geography.
Snorri also names Iðavöllr, the plain at the centre where the gods first built temples and forges, played at board games with golden pieces, and — in Völuspá's closing stanzas — meet again after the world ends and find the old pieces lying in the grass.
Sky, or somewhere you can ride to?
The sources will not commit. Bifröst runs from Ásgarðr down to Miðgarðr, which implies elevation, and Snorri says the gods ride up it daily. But Skírnismál's messenger rides out to Jötunheimr overland, Thor walks and wades, and the giants arrive on foot. The frontier between Ásgarðr and Jötunheimr is described as a place you can travel to and be attacked across — a border, not an altitude.
The wall itself is the most important thing about the place, and it is the point of the founding story. Norse cosmology is organised by enclosure: Ásgarðr is walled, Miðgarðr is fenced, and everything outside both is útgarðr, the outyards. Ásgarðr is a farmstead the size of the world, with a boundary that requires constant defending — which is what Thor is for.
Snorri's Troy
The Prose Edda's Prologue and Ynglinga saga both offer a completely different account, and it is not mythology at all. Snorri identifies the Æsir as men from Asia — deriving Æsir from Asia, which is false etymology — who came out of Troy, settled in the north, were mistaken for gods by the local population, and became the ancestors of Scandinavian royal houses. In this version Ásgarðr is either Troy itself or a city in Asialand near the Don, and Þórr becomes a Trojan prince descended from Priam.
Nothing in the Eddic poems supports any of it. It is euhemerism — the standard medieval Christian technique for handling pagan gods, deployed by a writer who needed a way to preserve the material without endorsing it, and who also wanted a Trojan pedigree for his patrons, exactly as English and Frankish chroniclers had claimed one for theirs. It should be read as a preface written to make publication safe, not as a variant tradition.
The version most people now hold
Marvel's Asgard is a golden city on a flat disc in space with a rainbow bridge, ruled from a throne room, with a monarchy, a succession crisis and a standing army. That image is now so dominant that it colours almost every popular reference.
The medieval Ásgarðr has no throne room, no succession, no capital city and no space. It has a wall built by a swindled giant, a plain with a board game on it, a scatter of halls belonging to individual gods, and a high seat called Hliðskjálf from which Odin can see everything — a piece of furniture, not a government. See the Norse tradition overview for how much of the systematised pantheon comes from one thirteenth-century writer, and Ragnarök for what happens to the wall in the end.
Is Ásgarðr destroyed at Ragnarök?
The poems are less explicit than the retellings. Völuspá describes the sun turning black, the earth sinking into the sea, steam and flame playing against heaven itself, and Surtr's fire covering everything — but it does not narrate the fall of a city. The gods leave to fight, the fighting happens on the plain Vígríðr, and afterwards a new earth rises. Whether the halls burn or simply become irrelevant is not stated, and the survivors returning to Iðavöllr to find the golden game pieces suggests continuity of place rather than annihilation of it.
Why is Freyja the price the builder asks for?
Because it is a formula. The sun, the moon and the goddess appear together as the giants' standing demand in more than one story — Þrymr asks for Freyja as the ransom for the hammer, and other giants seek her elsewhere. The pattern reflects a cosmology in which the jötnar are the older powers who want the world's valuables transferred back: light, time and fertility, the three things that make an inhabited world possible. It also means that Freyja's personal willingness is never once consulted by anyone proposing the trade, and the one time she is asked directly, in Þrymskviða, her answer shakes the hall.