The national unemployment rate — 9.1 percent in May — paints a grim political picture for President Obama as he turns his attention to the 2012 race.

But dig slightly further into the numbers and the economic news is far less ominous for him.

According to a state-by-state analysis conducted by Matt McDonald, a partner at the GOP-aligned Hamilton Place Strategies, the unemployment rate outpaced the national average in only four swing states last month: Florida, Michigan, Nevada and North Carolina.

Of that quartet, Nevada is in the toughest economic shape by far, with a 12.1 percent unemployment rate. Florida (10.6 percent) and Michigan (10.3 percent) have double-digit jobless rates, while North Carolina’s 9.7 percent keeps it slightly above the national average.

Those four states will account for 66 electoral votes in 2012. Both parties are likely to target 10 states that have unemployment rates below the national average — Colorado, Iowa, Indiana, Minnesota, New Hampshire, New Mexico, Ohio, Pennsylvania, Virginia and Wisconsin. Those states have a total of 106 electoral votes.

That means Obama could lose all four states where unemployment is above the national average and — assuming he can retain the other states he won in 2008 — still win a relatively comfortable reelection with 299 electoral votes.

“All of this is in the context of a pretty bad economy, but if I were sitting in the White House, the silver lining is that the economy is less bad in the places the president really needs to win,” McDonald said.

There are caveats, of course.

First, the national unemployment figures tend to have a trickle-down effect — meaning that the longer the rate remains high nationally, the more likely that pessimism about the country’s financial future could seep into swing states.

Both Ohio and Colorado had an unemployment rate of 8.6 percent in May, just half a point below the national average. Wisconsin and Pennsylvania each stood at 7.4 percent. Those four states will reward a total of 57 electoral votes in 2012, more than enough to cost Obama the presidency if he lost them and the states mentioned above.

Second, in each of the 14 swing states, the unemployment rate has risen from where it stood in October 2008 — just a month before he beat Sen. John McCain (R-Ariz.) to claim the presidency. The increases range from marginal — just a 0.7-point jump in Minnesota and New Hampshire — to the nearly catastrophic in places such as Nevada (up 4.4 points) and Florida (up 3.6).

Obama will continue to make the argument that he inherited a dismal economic situation and that things would have been far worse were it not for the policies his administration put in place.

But by the numbers alone, the Republican nominee probably will be able to make a forceful case against Obama built on the message: “Are you better off now than you were four years ago?”

Third, Obama is expected to carry a large number of states in 2012 where the unemployment rate is well above the national average.

The 14 states, plus the District of Columbia, considered safe for Obama in 2012 comprise 186 electoral votes; of that total, 90 are in states where the unemployment rate outstrips the national average — including California (55 electoral votes), where 11.7 percent of the population was unemployed in May.

That reality creates the possibility (though not the probability) that a few of those safer states could slip into the more competitive category between now and November 2012 if their economies don’t recover sufficiently.

There’s little doubt that the 2012 election is shaping up as a referendum on Obama’s handling of the economy. And while the macro numbers on the economy aren’t great for the president’s political prospects, the micro numbers are significantly better.

Given that a presidential election is less a single national contest than a series of state-by-state battles, the unemployment numbers should give the White House a glimmer of political optimism on the economy.