Image copyright Reuters Image caption Mr Sigley arrived in Beijing on Thursday

An Australian student who lived and worked in North Korea for over a year has been released from detention.

It's not known why Alek Sigley was detained - in his many public writings, the 29-year-old avoided political criticism of North Korea, instead describing the quirks and minutiae of society.

But how did he get there in the first place? And how many expats live in a nation largely sealed off to the world?

Who are the foreigners in North Korea?

Broadly, they can be divided into two groups: Westerners and Chinese.

China is North Korea's strongest and closest ally, and since relations improved between the two nations last year, the number of Chinese tourists visiting has surged, says Prof Dean Ouellette from Kyungnam University in South Korea.

He estimates that up to 120,000 Chinese tourists visited in the past year. In contrast, fewer than 5,000 Western tourists visit each year - and the number of Western residents is even lower.

North Korea researcher Andray Abrahamian, a frequent visitor to the country, estimates there to be only about 200 Westerners in the country.

Almost all of them are based in the capital, Pyongyang, and are tied to the handful of diplomatic missions, humanitarian aid missions, or are linked to the universities - including the Pyongyang University of Science and Technology, which has an exchange programme for teachers.

Is it hard to get in?

Most Westerners living in North Korea are there in "fairly specialised circumstances", says Dr John Nilsson-Wright, an international relations expert from Cambridge University and Chatham House.

"It's relatively unusual for people to spend a very long episode of time in North Korea, they're usually with some sort of government programme for a set time and numbers are quite small," he tells the BBC.

Outside of those areas, even accessing a visa for an NGO worker can be very difficult. Organisations need to secure a North Korean partner or sponsor who can vouch for them, says Prof Ouellette.

"The scrutiny process would be more thorough and probably involve the ministry of state security for anyone attempting a longer-term stay," he says.

What about Alek Sigley?

Alek first visited North Korea on a tourist visa in 2012, before setting up his own tour company.

He went on to lead dozens of trips to the state, building up the networks he needed to apply to study at Kim Il-sung University, the nation's top university.

"There is no open application process, and being accepted is often contingent on having contacts in-country," he wrote in a blog post.

"I had made some friends who were willing to vouch for me and help me apply, although reaching the finish line still took two years of email exchanges, a personal statement, a medical exam, and a police certificate confirming that I didn't have a criminal record."

Last April, he began his two-year masters degree on Korean literature. He noted that he was one of three Western students at his university - the other two men being from Canada and Sweden.

According to Chinese state media, the Chinese government offers 60 students full scholarships to North Korean universities each year. About 70 other Chinese students pay their own way there.

So what is it like living there?

In his blogs Mr Sigley wrote about the freedom he had, compared to tourists who must stick with their guide and only visit designated areas.

"As a long-term foreign resident on a student visa, I have nearly unprecedented access to Pyongyang," he wrote. "I'm free to wander around the city, without anyone accompanying me."

Media playback is unsupported on your device Media caption What it's like to live in North Korea

However, Mr Abrahamian says even as residents, Westerners often can't gain access to "plenty of places - restaurants and buildings and neighbourhoods" - partly because they lack items like the state-issued token to pay at a restaurant.

They also have to live their lives within a set of sensitive regulations. Mixing with locals is frowned upon. Public photography is risky.

"You can never take anything for granted when you're there," says Prof Nilsson-Wright.

He refers to the case of US student Otto Warmbier, who was jailed in North Korea in 2016 for 17 months after being accused of stealing a propaganda sign during a five-day tour.

He died just days after he was returned to the US in a coma. Following that, the US banned its citizens from visiting the state.

"As you see with the Warmbier case, well-meaning Westerners can fall foul of local regulations in a way that can be severe, and sometimes fatal," says Prof Nilsson-Wright.

Most Western expats are well aware of the risks says, Mr Abrahamian.

"[But] as hard as it is, it's worth trying to build connections to that society," he says. "We believe that contact is the best way of reducing suspicion and opening up the country."