Towards the remote, western edge of the Indian state of Rajasthan, surrounded by the Thar desert, the medieval fortress of Jaisalmer rises more than 20 storeys from the dusty landscape like a golden sandcastle. Built beginning in 1156, the sandstone citadel stands guard atop a triangular hill, complete with three layers of walls, four imposing gates and 99 turrets. Together with five other majestic forts in Rajasthan, Jaisalmer is a Unesco World Heritage site, and the striking honey hues of the yellow sandstone used in building this stronghold have inspired its moniker, the Golden City.

However, the citadel is more than just a significant historical and architectural landmark: more than 800 years after it was built, some 2,000 to 4,000 descendants of the castle’s earliest inhabitants continue to live inside its fortified walls, rent-free, as their ancestors were given the land by local kings in return for their services to the kingdom.

Today, not only is Jaisalmer the last inhabited ancient fortress in India, but it serves as something of a living monument, where life goes on among the narrow lanes and crowded courtyards in much the same manner as it did in the 12th Century.

You may also be interested in:
• The descendants of Alexander the Great?
• Where post is delivered at 4,440m
• A ghost island in the Indian Ocean

Vimal Kumar Gopa’s family has been living inside the fortress for more than 700 years, and the 44-year-old manages a textile gallery from his small Kundpada home. Historically, the neighbourhood has only been home to members of the priestly Brahmin caste, who worked as teachers and advisors to the local kings who ruled Jaisalmer from the 12th Century until as recently as the mid-1900s, and were given homes inside the citadel. Today, seven centuries and 23 generations later, Gopa’s extended Brahmin family owns 42 homes inside these ancient walls.

“Inside the fort, people having the same surname usually come from one family and live in the same neighbourhood,” Gopa said. Apart from Brahmins, the other dominant community living inside Jaisalmer’s fort is the Rajputs, a clan of northern Indian Hindu warriors who were responsible for the safety of the city that surrounds the citadel, as well as the walled fortress. According to Gopa, residents’ surnames are also an indication of their family’s caste in the past; Purohit and Vyas are other Brahmin names, while the Rajputs are called Bhatti, Rathore or Chauhan.

This is the only home we know

“My family has lived here for more than 400 years,” said Jitendra Purohit, a salesperson at a handcrafts showroom tucked into the fortress’s narrow lanes. “How many generations? I am not sure, but this is the only home we know.”

Gopa and Purohit’s remarkable family roots are quite common inside the Jaisalmer castle. In fact, stopping to chat with shopkeepers and residents lounging outside their homes, I heard the same story over and over again: most of them were born here and still work here – some having partly converted their homes into shops, cafes or guesthouses to make a living in the last few decades.

Jaisalmer was founded in the 12th Century by local leader Rawal Jaisal, who gave the city its name. Between the 16th and 18th Centuries, the kingdom flourished as an important stop on the Silk Road trading route that connected Europe with China via India, Afghanistan, Turkey and Egypt. Caravans of merchants and traders from the East, laden with bundles of silks, precious stones, spices, teas and whiffs of opium hanging in their wake would stop at one of Jaisalmer’s small inns with open courtyards seeking food, water and a place to sleep for the night. The local rulers prospered from the travellers’ stays, and wealthy city merchants built mansions (known as havelis), temples and inns both inside and outside Jaisalmer’s fortified walls.

Hundreds of years later, the only reminders of the area’s Silk Road significance are the abandoned villages, stone markers and dilapidated fortresses scattered across the barren desert landscape. Yet, the Golden City’s twisting lanes and turreted sandstone walls still lure caravans of visitors to its many hotels and restaurants. The desert winds now blow in camera-toting tourists by the busloads rather than merchants on camelback, but the city remains a stunning sandstone outpost where generations of residents have catered to travellers for centuries.

Today, the Jaisalmer fort is filled with a jumble of small teashops and cafes, guesthouses and homes, and temples and boutiques crammed against one another. Locals, particularly those living inside the fortress, continue to earn money from tourists. Some run restaurants serving simple mezze platters, while others sell exquisite handbags made of camel leather. Shopkeepers call out to passers-by to come in and inspect their flamboyant turbans, embroidered tapestries and ‘magic Viagra bedsheets’ said to inspire fertility. “No charge for looking, madam,” one called out from his plastic chair perched outside the shop.

The entire fort is one family

However, despite the thousands of visitors who pass through here every day, the fortress remains a tightknit society. Outside many of Jaisalmer’s homes, cheery paintings announce forthcoming weddings among the castle’s residents. The paintings list the names of the groom and bride along with the date of the marriage, usually under an auspicious symbol such as a figure of the elephant god Ganesha, who is also the god of new beginnings. According to Gopa, there is no need for formal invitations within this small, fortified community.

“The entire fort is one family,” Gopa said. “The boundaries begin and end with the main gate known as Akhrey Prol that separates the town from us. Whether it is a marriage or a death, all of us come together to observe it.” Purohit also added to this, saying, “A couple of years [ago], when my mother had a heart attack, neither my brother [nor] I was at home, but my neighbours took her to the hospital. This ‘harmony’ is what I like most about living here, and it has always been this way in this community for centuries.”

From the citadel’s main gate, a winding path lined by shops selling metal jewellery and beaded handicrafts greets travellers. Residents on their motorbikes and auto-rickshaws carefully weave their way up the path, honking through a sea of pedestrians. Jaisalmeri women in flowing skirts and colourful blouses, heads covered with bright dupatta scarves, carry prayer offerings filled with fresh flowers and aromatic incense sticks to the temples inside the fort.

One of the lanes up on the hillock leads to the central Dusshera Chowk square and the Baa Ri Haveli, a 450-year-old mansion-turned-museum showcasing artefacts from everyday life in the fort from the 15th Century to the present. Walking through the dozens of tiny rooms filled with misshapen coins, ancient maps, fading sepia photographs, cooking utensils, ornate turbans and other remnants of the past, what struck me is how much of this history still lives on in these lanes.

Brightly coloured cloth turbans, similar to the faded ones on display, can still be seen on the heads of fort residents, while traditional kitchens still use the same brass and bronze plates and pans. Gopa had described how Holi (a Hindu festival of colours) and Diwali (a festival of lights) were celebrated communally in much the same fashion as they had been hundreds of years ago – just as the daily worship rituals in the numerous Hindu and Jain temples inside Jaisalmer’s walls have remained the same over time. Today, this museum serves as a testament to the citadel’s proud history, but restoring the ancient building was no easy feat.

“The mansion itself was in disrepair,” said the museum’s manager, Rakesh Vyas, who has lived inside the Baa Ri Haveli mansion his whole life and is a direct descendent of the original family who owned it. Vyas described the long and painstaking process of restoration and the compilation of these artefacts. “We didn’t have any support from the government or anyone else,” he said.

This governmental lack of interest is not particularly surprising, Gopa later explained. The fortress is now a protected heritage monument, not under the direct control of the state or central government, but the Archaeological Survey of India (ASI), a government body responsible for the protection and conservation of the country’s temples, forts and archaeological sites. And while the ASI has mandated that no fort resident can sell his property to an outsider or alter the facade in any way, financial support for the maintenance of the fort, particularly its private spaces, has not been forthcoming.

Life is changing for us in many ways, but we hope that... our children and their children will also be able to live here

It is not only the mansions, but the fort itself that is in danger of ruin. It is built on soft sedimentary rock and has an ancient drainage system that has been seeping steadily and directly into the foundations of the fort for many years now. All this has been made worse by uncontrolled construction and repair activity inside the fort, which means that many parts of the sandstone walls have crumbled. This magnificent fortress may have weathered the elements and survived multiple attacks by invading armies for more than eight centuries, but its future remains uncertain.

As Gopa said with a touch of wistfulness, “Of course, life is changing for us in many ways, but we hope that, just like our forefathers, our children and their children will also be able to live here.”

Join more than three million BBC Travel fans by liking us on Facebook, or follow us on Twitter and Instagram.

If you liked this story, sign up for the weekly features newsletter called "The Essential List". A handpicked selection of stories from BBC Future, Culture, Capital and Travel, delivered to your inbox every Friday.