As he ran his practiced eye over the lie of the land - taking in the steep cliffs on two sides, the plateau, the view out to sea, the convenient well and countless other details - Lord Gosamaru would have realised very quickly that this was the ideal position for his castle.

Already lord of the castle of Zakimi, on the west coast of the main island of the Ryukyu Kingdom, as Okinawa was at the time, Gosamaru had built a reputation as being loyal to the king and designer of the most impregnable fortresses in the land.

A rudimentary defensive position had stood on the site since the middle of the 14th century but, when Gosamaru arrived, in 1440, to keep an eye on another lord who was becoming restive, he set about developing Nakagusuku into one of the key fortifications on the islands.

Using the skills and knowledge he had acquired over decades of attacks and counter-attacks with neighbouring clans, Gosamaru ordered the addition of enclosures that extended the castle's profile along the ridge, including a thick defensive wall built around the Ufugaa well, critical in a time of siege. And while aesthetics and form may not have been a priority for a man looking to protect his position, Gosamaru managed to create a structure that was both pleasing to the eye and functional.

And so it remains to this day.

Atop jagged cliffs that tower 150 metres above the the coastal town of Yagi, Nakagusuku Castle's series of six enclosures are protected by thick limestone walls punctuated by arched gateways, carefully engineered steps and the well, which enhanced the prestige and importance of the entire structure. One of the enclosures has been identified as having been set aside for the training of war horses, while a cave hollowed out of an outcropping apparently served as a forge for making weapons.

Visitors can climb on the walls that circle the outer extremities of the fortress and offer spectacular views in all directions. The Katsuren Peninsula appears to the left of Nakagusuku Bay, with the islands of Tsuken and Kudaka on the horizon. Birds of prey wheel effortlessly overhead.

The entire structure was damaged during the American invasion of Okinawa in 1945 - Japanese defenders had once again recognised its strategic importance - and it was left to fall into disrepair after the war.

It was not until 1995 that a restoration and conservation project was started, and work continues on a stretch of the outer wall of the main enclosure. Nakagusuku was recognised by Unesco in November 2000, along with Okinawa's other surviving castles, as a world heritage site.

Historians estimate that Okinawa was once peppered with as many as 500 sets of fortifications, constructed as defences by the clans that populated the islands of the emerging Ryukyu Kingdom. Known as gusuku, virtually all have been destroyed in the intervening centuries - although tantalising outlines of what were once impressive fortifications can be found in the tropical undergrowth throughout the archipelago. A mere six castles remain in recognisable condition.

Arguably the structure that best captures the differences in design between fortresses in Okinawa and mainland Japan is Zakimi Castle, another of Gosamaru's creations. Instead of being ruler-straight and precisely angled, Zakimi's walls are all gentle curves and flowing lines. Its defences are graceful and almost fluid, complementing the natural curves of the coast to the west and Okinawa's jungle-clad mountains as they stretch away to the north and east.

An arched gate serves as passageway through the undulating outer wall, the only way into the first of the two courtyards that make up the castle. This is the oldest surviving example of an arched gate that uses the unique keystone masonry of the early years of Ryukyuan history. The courtyard is covered with a lush green grass where once there would have been all the trappings of a local lord. A steep set of limestone steps - marked by footsteps since work began on this site in 1416 - leads visitors into the second passageway and the seat of power.

Marked on the ground are the footings of the lord's residence, although little else remains of the lives that were led here 600 years ago. The castle was built on a hilltop above the village of Yomian to control movement up and down the west coast of Okinawa.

Before the second world war, the Japanese military turned the castle into an artillery emplacement. Also damaged during the invasion, Zakimi Castle suffered further indignities when it was pressed into service as a radar station by the United States military after the war, with some of the exterior walls destroyed so equipment could be sited.

While the fortresses of Zakimi, Nakagusuku and others across the islands have been preserved, they have not been fully returned to their former glories. Restoration work goes on at Shuri Castle, which overlooks the city of Naha, in the south of the main island, but much has already been achieved here and a walk within its walls gives a good idea of what it must have been like to live in the days of the Ryukyuan kings.

The fortifications on this elevated site are believed to date back to the 14th century and the first formal castle was used as the royal seat for King Sho Hashi from 1406. Over the following six centuries, the castle was enlarged, improved, destroyed by fire, rebuilt, burned to the ground in another blaze and once more rebuilt. In the fierce fighting for Okinawa in the closing days of the second world war, Shuri Castle was yet again razed.

Painstaking efforts have again restored most of the sprawling complex to its former glory - the exterior walls are gracefully curved and the wooden buildings are stained vermillion with paulownia oil and lacquer - although work continues to reconstruct the eastern reaches of the castle.

Shuri Castle reflects the influences of China, mainland Japan and the indigenous Ryukyuan culture in its design.

Beyond the shureimon, the two-storey decorative gate that leads into the castle grounds, is the sonohyan-utaki, a limestone shrine where the king would have paused to offer prayers before setting out on his journeys throughout the kingdom. A little further on is the kankaimon, the first gate into the concentric walls that protected the royal family. The roof of the gate has upturned eaves that are reminiscent of Chinese temples and, built around 1477, was where representatives of the Chinese emperors were welcomed.

A series of gates leads deeper into the castle and the administrative buildings. Within the final sub-courtyard is the suimi-utaki, a sacred site that, legend states, was created by the hand of god and was the most important place of worship within the castle. A stone wall surrounds a banyan tree and a kurotsugu tree and restoration work in this part of the castle was completed in 1977.

The floor of the final open space, the una, is striped from side to side in red and white. Presiding over it is the seiden hall; three storeys tall, painted in red with scarlet tiles and golden dragons baring their fangs at each other across the roof, this was the central structure of the Ryukyu Kingdom for 500 years.

The largest wooden building on the islands, the seiden contains the richly decorated chambers where the rulers of this kingdom carried out the ceremonies and affairs of state, seated on a throne of red and gold.

Getting there: Hong Kong Airlines flies from Hong Kong to Okinawa daily.