Nigerian Islamist group Boko Haram has told the BBC it carried out the series of bombings after President Goodluck Jonathan's inauguration on Sunday.
The worst incident was at an army barracks in the northern city of Bauchi in which at least 14 people died.
A sect spokesman said it was also responsible for killing the brother of the Shehu of Borno, one of Nigeria's most important Islamic leaders.
The sect has been behind numerous recent assassinations in Borno state.
It is opposed to Western education and accuses Nigeria's government of being corrupted by Western ideas.
Clashes in Borno's state capital, Maiduguri, between the Boko Haram and the police in July 2009 left hundreds of people dead, mainly members of the sect.
For the past eight months, sect members have been fighting a guerrilla war in Borno, killing policemen and people they believe were helping the security services in the fight against them.
Sect spokesman Abu Zayd told the BBC's Hausa Service that serving members of the Nigerian army had been used to carry out the bombings in the Bauchi barracks on Sunday.
Some soldiers wanted to join the sect and had been used as a way of testing their loyalty to Boko Haram, he said.
But Nigerian army spokesman Brig-Gen Raphael Isa rejected the allegation.
"It is not correct. Let him publish the names of those pledging loyalty to Boko Haram," he told the BBC News website.
"This is not a banana republic. We are one army united and very very loyal," he said.
Mr Zayd said the sect was also behind the killing of Abba Anas Ibn Umar Garbai, who was killed by gunmen outside his home in Maiduguri on Monday evening.
''We are the ones responsible for the killing of the junior brother of the Shehu of Borno," he said.
The Shehu of Borno is one of Nigeria's most prominent religious figures - second only to the Sultan of Sokoto, the spiritual leader of Nigeria's Muslims.
"As we always say, these traditional institutions are being used to track and hunt us, that is why we attack them," Mr Zayd said.
"We are doing what we are doing to fight injustice, if they stop there satanic ways of doing things and the injustices, we would stop what we are doing.''
Officials say 16 people died in the explosions in Bauchi, Zuba, Zaria, hometown of Vice-President Namadi Sambo, and Maiduguri.
The first attack came only hours after President Jonathan was sworn in for his first full four-year term of office in the capital, Abuja.
Mr Jonathan was promoted from vice-president after northerner Umaru Yar'Adua died in office in 2010.
April's election was largely considered free and fair, but hundreds of people were killed in three days of rioting and reprisal killings in northern towns following the announcement of the result.
Mr Jonathan, a southerner, secured nearly 60% of the vote in the election. His main challenger, northern Muslim and former military ruler Muhammadu Buhari, came a distant second with almost 32%.
Nigeria is divided by rivalry between the predominantly Muslim north and the mainly Christian south, which also have cultural, ethnic and linguistic differences.
Analysts say that Mr Jonathan will have to tackle this north-south rivalry and also the simmering tension in the oil-producing Niger Delta.
To win at the first round, a candidate not only needs the majority of votes cast, but at least 25% of the vote in two-thirds of Nigeria's 36 states. Goodluck Jonathan, of the PDP, reached that threshold in 31 states; runner-up Muhammadu Buhari of the CPC only did so in 16 states.
Nigeria's 160 million people are divided between numerous ethno-linguistic groups and also along religious lines. Broadly, the Hausa-Fulani people based in the north are mostly Muslims. The Yorubas of the south-west are divided between Muslims and Christians, while the Igbos of the south-east and neighbouring groups are mostly Christian or animist. The Middle Belt is home to hundreds of groups with different beliefs, and around Jos there are frequent clashes between Hausa-speaking Muslims and Christian members of the Berom community.
Despite its vast resources, Nigeria ranks among the most unequal countries in the world, according to the UN. The poverty in the north is in stark contrast to the more developed southern states. While in the oil-rich south-east, the residents of Delta and Akwa Ibom complain that all the wealth they generate flows up the pipeline to Abuja and Lagos.
Southern residents tend to have better access to healthcare, as reflected by the greater uptake of vaccines for polio, tuberculosis, tetanus and diphtheria. Some northern groups have in the past boycotted immunisation programmes, saying they are a Western plot to make Muslim women infertile. This led to a recurrence of polio, but the vaccinations have now resumed.
Female literacy is seen as the key to raising living standards for the next generation. For example, a newborn child is far likelier to survive if its mother is well-educated. In Nigeria we see a stark contrast between the mainly Muslim north and the Christian and animist south. In some northern states less than 5% of women can read and write, whereas in some Igbo areas more than 90% are literate.
Nigeria is Africa's biggest oil producer and among the biggest in the world but most of its people subsist on less than $2 a day. The oil is produced in the south-east and some militant groups there want to keep a greater share of the wealth which comes from under their feet. Attacks by militants on oil installations led to a sharp fall in Nigeria's output during the last decade. But in 2010, a government amnesty led thousands of fighters to lay down their weapons.