Four years ago WikiLeaks founder Julian Assange sought refuge in Ecuador's UK embassy, a small flat in Knightsbridge, west London, that has become his de facto residence.

Inside, Mr Assange reportedly sleeps in a makeshift bedroom, exercises to maintain fitness, celebrates birthdays with embassy staff, and monitors his food intake for poisoning, all the while continuing to work on his WikiLeaks project.

Mr Assange entered the embassy on June 19, 2012 to avoid extradition to Sweden over a rape allegation, which he denies.

If extradited to Sweden, Mr Assange fears he will be sent to the United States and put on trial for publishing classified documents.

What is diplomatic asylum? Diplomatic asylum is the extension of diplomatic immunity privileges to a foreign national

Diplomatic immunity is a historic legal concept that grants diplomats exemption from local laws

It originally was born out of a need for state-to-state communication without fear of "shooting the messenger"

Immunity has since expanded to include missions, consulates, envoys and personal belongings

The concept was legally codified in the 1961 Vienna Convention on Diplomatic Relations

Diplomatic asylum, however, is not officially recognised under international law

It remains a highly controversial practice

The statute of limitations on the rape allegation will not expire until 2020, but Ecuadorian authorities have stated Mr Assange can remain in the embassy as long as he wishes.

Mr Assange has compared living inside the embassy to life on a space station. But as weird as his current situation may be, it is not unique.

History is littered with hundreds of cases of people who sought refuge through another nation's diplomatic inviolability privileges, ranging from Tiananmen Square dissidents to overthrown leaders of state.

However, diplomatic asylum remains a vaguely defined practice that is highly controversial and, as a result, often has strange and unpredictable outcomes.

Here are a few examples of individuals who sought refuge under another nation's diplomatic immunity, and how it worked out for them in the long run.

Fang Lizhi, Tiananmen Square dissident

Fang Lizhi was a Chinese astrophysicists who is widely regarded as one of the leading proponents of the Tiananmen Square protests of 1989.

Chinese astrophysicist Fang Lizhi. ( AFP, file photo )

On June 5, 1989 — the day after the Chinese government began their brutal crackdown on the protests — Fang and his wife Li entered the US embassy in Beijing, where they were granted asylum.

Over the course of the next year, Fang and his wife remained in the embassy after being placed at the top of a Chinese government wanted list.

At the time, US ambassador James Lilley described Fang as "a living symbol of our conflict with China over human rights".

On June 25, 1990, after over a year of highly contentious negotiations between the US and China, the Chinese government ultimately allowed Fang and his wife to leave the embassy and board a US military plane to the UK.

Fang then continued to live and work as an academic in the UK and later in the US, where he passed away in 2012.

Mohammad Najibullah, former Afghanistan president

Mohammad Najibullah was a former Soviet-backed president of Afghanistan, who headed the country from 1986 to 1992.

After the fall of the Soviet union in 1991, Najibullah's military and economic aid was cut amid a brutal war in the country between his forces and the US-backed mujahideen.

Former Afghan president Mohammad Najibullah. ( Reuters: Andrew Wong, file )

Najubullah's government eventually collapsed, leading to his ousting from power in April 1992.

Najibullah then asked the United Nations for amnesty, which was granted, but his attempt to flee to the airport was thwarted by mujahideen militants, forcing him to race to the UN compound in Kabul where he was granted diplomatic asylum.

Najibullah remained in the UN compound for the next four years, in a high-profile case that saw continued attempts to negotiate his safe passage out of the country.

However in 1994, a much more brutal oppositional Islamic group spawned out of the mujahideen came onto the scene — the Taliban. They eventually took over Kabul in 1996.

The Taliban, who did not recognise Najibullah's diplomatic asylum, eventually stormed the UN compound on September 28, 1996, and dragged the former president out.

Najibullah was then castrated, dragged to death in the streets tied to the back of a truck, and publicly hanged as a symbolic gesture to the world that the Taliban had taken control.

Jozsef Mindszenty, Catholic cardinal during WWII

By far one of the longest recorded cases of an individual being granted diplomatic asylum, Jozsef Mindszenty, the former head of the Catholic Church in Hungary, spent 15 years living in a US embassy in Budapest after the end of World War II.

For decades before and during the war, Mindszenty had stood as a staunch opponent of fascism and communism in Hungary, where he relentlessly advocated and supported religious freedom.

A 1962 photo of Josef Mindszenty. ( Wikimedia Commons )

After being detained by the country's pro-Nazi regime forces during WWII, Mindszenty was tortured and subsequently handed a life sentence in a controversial 1949 trial that garnered worldwide condemnation.

Mindszenty was eventually set free during the Hungarian Revolution in October 1956, and was granted diplomatic asylum by the United States soon after when the Soviet Union invaded Hungary.

The cardinal lived in the US diplomatic mission for the next 15 years, unable to leave the grounds. And while repeated attempts were made to escort him out of the country, his health continued to deteriorate.

Mindszenty was reportedly considered an inconvenience in the smallish diplomatic mission, and requests by the US for more space were reportedly denied on the condition that Mindszenty be handed over to Hungary.

However, in 1971, Mindszenty was ultimately declared a "victim of history" by Pope Paul VI, and was granted permission to leave Hungary for Austria, where he died four years later aged 83.

So what will happen in Assange's case?

Short answer: it is impossible to know.

"Cases of diplomatic asylum, while not unique in theory, are always unique in the way they unfold, due to murky guidelines and the diplomatic stress executing a political act on another country's territory entails," Amir Matar, an independent legal adviser on public international law, told the ABC.

"With Assange, there is no way of knowing what will happen, all options are on the table."

Possible scenarios for the end of Mr Assange's diplomatic asylum case have been put forward, and range from him handing himself over to British police, to seeking a United Nations ruling on his "arbitrary detention", to potentially carrying him out of the embassy and country in a diplomatically immune "body bag".

"But you have to remember, the decision to take Assange on as a diplomatic asylum seeker can always be argued by the UK and the US as a case of abusing diplomatic immunity," Mr Matar said, despite both the UK and the US having committed the same practice in times past.

"Legally speaking, [granting a foreign national diplomatic asylum] is not officially recognised by international law.

"So carrying him out in a body bag, surrounded by an envoy of British police officers all the way to the airport or British borders, while conceivable, would be seen as an extreme abuse of diplomatic privileges."

Mr Matar added that while Mr Assange was highly wanted, maintaining diplomatic relations was universally considered far more important.

"There's no way to know what will happen, so his situation should be seen as another real-time study of the legal implications of granting a foreign national diplomatic asylum," he said.

"He could stay there for 20 years, or he could leave tomorrow, we'll just have to see how it plays out."

ABC