Officials said they were killed in a fierce gunfight overnight, witnesses say.
They say civilians were hit by stray bullets in the fighting, which lasted for hours. The army says none of soldiers died.
Boko Haram has carried numerous attacks in northern Nigeria, killing hundreds of people since 2009.
The authorities have blamed the latest violence on Boko Haram, which has its stronghold in Maiduguri – there has been no comment so far from the group.
“Some suspected Boko Haram terrorists attempted to open fire on (security) operatives but could not succeed,” said army spokesman Col Victor Ebhaleme.
“We have so far shot dead 16 of the terrorists during a shoot out,” Col Ebhaleme said.
Tuesday’s late-night attack took place in Maiduguri’s district of Lawan Bukar.
After the fighting, Col Ebhaleme say troops had also seized weapons and explosives during house-to-house searches.
Meanwhile, in a separate attack in the city of Kano, suspected Boko Haram gunmen opened fire on Tuesday night, killing a retired policeman and two serving officers.
Boko Haram – whose name means “No to Western education” – wants to impose Sharia law across Nigeria.
It has targeted churches, including the most recent suicide attack on Sunday on a church in the northern state of Bauchi, in which at least nine people were killed by a blast and 30 other people injured.
The group has also attacked schools, police stations, and other government buildings.