The incident took place in northern state of Borno in which 13 militants of the radical Islamic sect were also killed.
The insurgents, who came with Hilux pick-up trucks, launched the attack in Bama, a commercial town about 187 km away from Maiduguri, yesterday, military spokesman Lt Col. Sagir Musa told reporters here.
In the incident, 22 policemen, 14 prison guards, two soldiers and four civilians were killed by the heavily-armed militants, Musa said.
Boko Haram has been a major terrorist group in Nigeria which has killed thousands through suicide attacks, bombings and shootings.
The group wants to install an Islamic caliphate in Nigeria, an oil rich African country with a population of 150 million people equally shared between the two major religions, Islam and Christianity.