To the outside world, the talk often appears to border on the lunatic, with the poor, hungry and electricity-starved nation threatening to lay waste to America’s cities in an atomic firestorm, or to overrun South Korea in a lightning attack.

Enemy capitals, North Korea said, will be turned “into a sea of fire.” North Korea’s first strikes will be “a signal flare marking the start of a holy war.” Pyongyang’s nuclear arsenal is “mounted on launch pads, aimed at the windpipe of our enemies.”

And it’s not all talk. The profoundly isolated, totalitarian nation has launched two rockets over the past year. A February nuclear test resulted in still more U.N. sanctions. Another missile test may be in the planning stages.

But there is also a logic behind North Korea’s behavior, a logic steeped in internal politics, one family’s fear of losing control and the ways that a weak, poverty-wracked nation can extract concessions from some of the world’s most fearsome military powers.

It’s also steeped in another important fact: It works.

At various points over the past two decades, North Korea’s cycles of threats and belligerence have pressured the international community into providing billions of dollars in aid and, for a time, helped push South Korea’s government into improving ties.

Most importantly to Pyongyang, it has helped the Kim family remain in power decades after the fall of its patron, the Soviet Union, and long after North Korea had become an international pariah. Now the third generation of Kims, the baby-faced Kim Jong Un, is warning the world that it may soon face the wrath of Pyongyang. If the virulence of Kim Jong Un’s threats have come as a surprise, he appears largely to be following in his father’s footsteps.

“You keep playing the game as long as it works,” said Christopher Voss, a longtime FBI hostage negotiator and now the CEO of the Black Swan Group, a strategic advisory firm focusing on negotiation. “From their perspective, why should they evolve out of this? If it ain’t broke, don’t fix it.”

Like hostage-takers, the North Koreans find themselves backed into a corner of their own creation, surrounded by heavily armed foes and driven by beliefs that seem completely illogical to everyone else. “From the outside, it makes no sense,” said Voss. “From the inside it makes all the sense in the world.”

But the North Koreans also have repeatedly and purposefully backed themselves into those corners, terrifying the world with missile launches and nuclear tests that often end with North Korea getting more international assistance.

Take the early 1990s, when Pyongyang backed away from a nuclear weapons program in exchange for promises of $5 billion in fuel and two nuclear reactors. Or the late 1990s, when North Korea launched a suspected missile over Japan and dispatched a submarine into South Korean waters. But by 2000 the leaders of both Koreas were sitting down for a historic summit in Pyongyang. Then, in 2006, North Korea terrified the world with a nuclear weapons test, but a year later ratcheted back its nuclear program in exchange for aid and political concessions.

The predictability of the pattern is an important sign to scholars that at least part of what is going on has been carefully considered, and that Pyongyang has clear goals in mind.

In other words: No matter how irrational the situation looks, North Korea’s leadership is not crazy.

Instead, many observers believe, North Korea simply wants the world to believe it is crazy, leveraging the international community’s fear of unpredictability to magnify its power.

The result is obvious.

“How many countries have been overrun since the end of the Cold War? How many dictators have been deposed?” asked Rodger Baker, an analyst for Stratfor, a geopolitical intelligence firm. “And where is North Korea? It’s still there.”

The North Korean leadership also retains, as far as is known, the support of its people. Their lives are often miserable, hunger is widespread and indoor toilets are a luxury to many. But other than a few whispered rumors of minor military rebellions, there has been no sign of revolt.

To many North Korean exiles, the recent round of threats are really about retaining that internal support.

“Kim Jong Un is so young,” said Nam-su Han, who fled North Korea as a young man after his father, a military officer, was executed, and who now runs a Seoul-based activist group. “He needs to gather the support of his citizens … and he’s using this (belligerence) to make the people come together.”