When North Korea hinted it had a hydrogen bomb last month — twice — it was largely brushed off as bluster. Now that it's claiming to have actually tested one, it is being taken a lot more seriously and a storm of outraged alarm, criticism and threats of sanctions are once again raining down on its head.

Mission accomplished? Quite possibly, from Pyongyang's perspective.

Skepticism remains high over exactly what was detonated Wednesday, but North Korea's ruling regime is probably the most adept in the world at calculating the benefits and risks of ratcheting up tensions and alienating even its closest allies to get what it wants. And what does it want? That's extremely hard to say since North Korea's other standout skill is keeping its real motives as murky as possible.

To much of the world, the reasons why the test was a bad idea seem obvious.

Pyongyang has almost certainly exposed itself to even tougher international sanctions on its already sputtering and underperforming economy. By ignoring China's efforts to discourage it from conducting nuclear tests, it has very publicly slapped its most important trading partner, and its key political cushion against the United States, in the face. It has strengthened the hand of its adversaries in the United Nations, who could push harder for punitive measures over human rights violations.

But at the heart of every decision the regime makes is one overriding concern: the survival of the regime itself, which depends on the glorification of its leader, Kim Jong Un, and the ability to keep at bay the United States and its allies, which Pyongyang considers to be an existential threat.

The North, officially the Democratic People's Republic of Korea, has long claimed it has the right to develop nuclear weapons to defend itself against the U.S., an established nuclear power against whom it has been in a state of war for more than 65 years. But to build a credible nuclear threat, the North must explode new nuclear devices — including miniaturized ones — so its scientists can improve their designs and technology.

Nuclear-tipped missiles could then be used as deterrents and diplomatic bargaining chips with the United States, which Pyongyang has long pushed to withdraw its troops from the region and to sign a peace treaty formally ending the Korean War.

"This test is a measure for self-defense the DPRK has taken to firmly protect the sovereignty of the country and the vital right of the nation from the ever-growing nuclear threat and blackmail by the U.S.-led hostile forces," the Korean Central News Agency said in a story announcing the detonation.

In a general sense, keeping the threat of invasion fresh in the minds of North Koreans is a tried-and- true method of bolstering unity and deflecting attention from other issues, such as the economy. Pyongyang's claim it was testing an H-bomb is also a classic move — what better way to boost the dramatic impact, and drum up national pride, than to trumpet that the North has a stronger, scarier weapon than ever before?

Hazel Smith, director of the International Institute of Korean Studies at the University of Central Lancashire in the U.K., said that on the diplomatic front North Korea does not worry about angering anyone.

"Every nuclear test that they've had has caused massive consternation in China," said Smith, who lived in North Korea in the late 1990s and early 2000s, working for the United Nations. "But the North Koreans have never been susceptible to letting China tell them what to do."

Instead, the North Korean government, she says, believes the military is the key to regime survival and that giving up nuclear weapons development — as Moammar Gadhafi did in Libya — simply leads to a government's downfall.

"The North Koreans are not led by diplomatic strategy anymore. They are led by a view that the military is what allows the regime to survive," she said. "You have a group of (ruling) families who don't want to see their power go, who don't want to end up in (the International Criminal Court in) The Hague."

By going ahead with the test, Kim — whose birthday is Friday — might well be playing to that domestic audience.

North Korea's ruling party, fresh off of a huge celebration to mark its 70th anniversary in October, will hold its first congress in 36 years in May. The event, strongly hyped in the North Korean media, will be watched closely by North Korean elites and North Korea watchers abroad for signs of whether the young Kim — still in his early 30s — will step out of his father's and grandfather's shadows and assert his own leadership more boldly.

If the international fallout from the test doesn't prove to be too unmanageable, having it under his belt could allow Kim to go into that meeting with bragging rights that neither of his predecessors had, along with a bolstered position among North Korea's powerful military and nuclear weapons bureaucracies.

John Delury, a professor at Seoul's Yonsei University, said Pyongyang has little going on diplomatically with Seoul and warming ties last year with Beijing did not go very far. The Obama administration, meanwhile, has made clear it isn't interested in improving ties with North Korea unless Pyongyang gives up its nuclear weapons program.

"So he takes a little bit of a blow" by infuriating friends and enemies alike, Delury said, but in return North Korea gets immense international attention, Kim can claim a major new weapon and powerful officials inside his own regime are placated.


Eric Talmadge is the AP's Pyongyang bureau chief. Follow him on Twitter at twitter.com/EricTalmadge. AP writer Tim Sullivan in New Delhi contributed to this analysis.