For more than a half-century, a mysterious caste system has shadowed the life of every North Korean. It can decide whether they will live in the gated compounds of the minuscule elite, or in mountain villages where farmers hack at rocky soil with handmade tools. It can help determine what hospital will take them if they fall sick, whether they go to college and, very often, whom they will marry.

It is called songbun. And officially, it does not exist at all.

The power of caste remains potent, exiles and scholars say, generations after it was permanently branded onto every family based on their supposed ideological purity. But today it is also quietly fraying, weakened by the growing importance of something that barely existed until recently in socialist North Korea: wealth.

Like almost all change in North Korea's deeply opaque society, where so much is hidden to outsiders, the shift is happening slowly and often silently. But in the contest for power within the closed world that Pyongyang has created, defectors, analysts and activists say money is now competing with the domination of political caste.

"There's one place where songbun doesn't matter, and that's in business," said a North Korean soldier-turned-businessman who fled to South Korea after a prison stint, and who now lives in a working-class apartment building on the fringes of Seoul. "Songbun means nothing to people who want to make money."

Songbun, a word that translates as "ingredient" but effectively means "background," first took shape in the 1950s and '60s. It was a time when North Korea's founder, Kim Il Sung, was forging one of the world's most repressive states and seeking ways to reward supporters and isolate potential enemies.

Historians say songbun was partially modeled on Soviet class divisions, and echoes a similar system that China abandoned in the 1980s amid the growth of the market economy there. In Korea, songbun turned a fiercely hierarchical society upside down, pushing peasants to the top of the caste ladder; aristocrats and landlords toward the bottom. The very top was reserved for those closest to Kim: his relatives and guerrillas who had fought with him against Korea's Japanese occupiers.

Very quickly, though, songbun became a professional hierarchy. The low caste became farmers and miners. The high caste filled the powerful bureaucracies. And children grew up and stepped into their parents' roles.

"If you were a peasant and you owned nothing, then all of a sudden you were at the top of the society," said Bob Collins, who wove together smuggled documents, interviews with former North Korean security officials and discussions with an array of ordinary North Koreans to write an exhaustive songbun study released this year by the Washington-based Committee for Human Rights in North Korea. While the songbun system theoretically allows for movement within the hierarchy, Collins said most families' standing today remains a reflection of their ancestors' position in the 1950s and '60s.

Generations after the system began, many of North Korea's most powerful people are officially identified as "peasants."

But starting in the mid-1990s and accelerating in recent years, songbun — long the arbiter of North Korean life — became one part of something far more complicated.

"Songbun cannot collapse. Because that would mean the collapse of the entire system," said Kim Hee Tae, head of the Seoul-based group Human Rights, which maintains a network of contacts in the North. "But people increasingly believe that money is more important than your background."

Despite its power, songbun is an almost-silent presence. Few people ever see their own songbun paperwork. Few low-caste families speak of it at all, exiles say, left mute by incomprehension and fear. It's only when young people stumble into glass ceilings, normally when applying to universities or for jobs, that they begin to understand the years of slights.

Eventually, most grow to understand and accept its power, but they rarely have more than a general idea of where they fit into the pecking order, experts said. In a country where secrecy is reflexive, the state simply denies it exists.

"This is all nonsense!" a North Korean government minder said, interrupting a visiting American journalist when he tried to ask a woman about her family's songbun. "People make up lies about my country!"

Certainly, few ordinary North Koreans understand the staggering and sometimes shifting complexities of songbun, which at its core divided the entire population into three main categories — "core," ''wavering" and "hostile" classes — and subdivided those into some four dozen subcategories.

North Koreans with songbun good enough for the top jobs will still likely get minimal salaries, but perks for the elite could include a good apartment in Pyongyang, regular electricity, access to quality medical clinics and easier admission to top schools for their children. In a culture where parents have immense influence over the choice of their children's spouses, high-songbun partners are prized.

But to be caught at the bottom, defectors say, is to be lost in a nightmare of bloodline and bureaucracy.

"My family was in the lowest of the lowest level," said a former North Korean coal miner who fled to South Korea in 2006, hoping to give his young sons opportunities outside the mines. "Someone from the state was always watching what we were saying, watching what we were doing ... The state treated us as if they were doing us a favor simply by allowing us to live."

The man, like other North Korean refugees interviewed for this story, spoke on condition he not be named, fearing that relatives still in the North would be punished.

When he was a boy he had hoped to be a doctor, or perhaps a government official. He was a top student, he says. But when colleges kept rejecting him, his father finally told him the truth: His father, it turned out, had been born in South Korea, served in its army and been taken prisoner during the Korean War. Like thousands of other southern POWs, he disappeared into the North's prison gulag, and then was forced into the coal mines.

With songbun like that, his choices were few. He would never become a government official. Getting into college, and perhaps eventually landing nonpolitical work, would have required impossibly large bribes. North Korea's growing network of small informal markets, a path out of desperate poverty for some, had yet to arrive in his village, deep in the countryside.

"I couldn't live my dreams because of my father," said the thin, ropy man, with the biceps of someone who spent 17 years swinging a pick deep underground.

But while North Korea is often portrayed as a Soviet throwback stranded in the 1950s, a reputation it earned with decades of isolation and single-family rule, strains of change do ripple beneath its Stalinist exterior. That has created a complex and uneasy relationship between songbun and wealth.

Most North Koreans have never met a foreigner, seen the Internet, or earned more than a couple hundred dollars a month — but those in a growing economic elite now fly to Beijing and Singapore to shop. It's a country where human rights groups say well over 100,000 political prisoners are held in a series of isolated prison camps, but where an exclusive European firm, Kempinski, hopes to be running a hotel soon.

The market economy first took hold during the rule of Kim Jong Il, the son of the nation's founder, who ran the country from the 1990s until his death in late 2011, when his son then took control. In the mid-1990s, poor harvests and the end of Soviet assistance lead to widespread famine.

Official controls relaxed as hunger tore at the country.

Reluctantly, the government allowed the establishment of informal markets, with ordinary people setting up stalls to sell food, clothes or cheap consumer goods. Since then, the government has alternately allowed the markets to flourish and cracked down on them, leaving many people working in legally gray areas. At the same time, state-sanctioned trade has also blossomed, much of it mineral exports to China.

While many defectors and analysts say songbun remains a commanding presence in everyday life, a handful feel the growth of markets has reduced the caste system to little more than a bureaucratic shell. But to some extent, in a murky economy where nearly any major business deal requires under-the-table payments, most analysts believe it is the same songbun elite that profits in the business world. They are part of an informal club that gives them access to powerful contacts. If they need help finalizing a black market business deal, they have people to call.

"Who gets the bribes?" asked Collins, who believes the caste system remains deeply entrenched. "It's the guys at the upper levels of songbun."

This is also a time when songbun often has a price, even if no one bothers quoting it in North Korea's unstable currency, the won.

"It costs five to ten pheasants to get into a good university," said Kang Cheol Hwan, a prominent North Korean defector, using North Korean slang for 10,000-yen Japanese bills, which show two of the birds and are worth about $125 apiece. "The price goes up as the background goes down."

While amounts like that remain unimaginable for most in North Korea, where the per capita GDP is estimated at $1,800 per year, the small consumer class is growing — and looking for ways to get ahead, no matter their songbun. While high-level government jobs remain restricted to those with excellent songbun, the low-caste also now have ways to get ahead. If they can afford it.

"Increasingly, there are ways to buy your way into jobs," said the former soldier and businessman, a short man with thick shoulders, huge hands and an expression frozen in a scowl.

Today, it's possible to make serious money in North Korea. There are Mercedes for the tiny population of truly rich, and Chinese-made sedans for the aspiring-to-be-rich. North Korean arrivistes can buy toddler-sized battery-powered cars for their children.

The ex-soldier lives in a tiny two-room apartment on the fifth floor of yet another Seoul high-rise, set amid a cluster of near-identical buildings, a concrete forest of middle-class anonymity. He doesn't want to talk about his songbun — though it becomes clear it was closer to the bottom than the top — but he says he eventually got a government job importing raw materials from China, then reselling them in North Korea.

"You can't get the jobs at the very top, but you can buy your way into the lower end of the top jobs," he said.

Before he was arrested and sent to prison for helping smuggle someone into China, he says he could make up to $5,000 a month — a fortune for a man raised in a mining village in the rugged, poverty-savaged northeast.

But is this changing system, with the ever-increasing power of money, any fairer than one based purely on songbun? Certainly it is no gentler.

Getting rich in North Korea isn't easy, with the bribes, the thugs and the risk of getting handed over to the authorities.

The people who succeed are often like the former soldier, with his air of menace and his run-ins with the law. What he describes as the ideological brutality of his youth has given way to something else, a hard-to-define tangle where it's often impossible to separate songbun from corruption and the Darwinian brutality of the market economy.

More than five years after he moved to Seoul, in some ways he still lives with that brutality.

You can see it in the three locks he has on his front door. And you can hear it when you leave, and all three quickly click shut behind you.