Col Sani Kukasheka Usman yesterday said the two were sappers, or combat engineers, who worked in an explosive ordinance unit in the northeast where Boko Haram commits most attacks, and may have trained insurgents in bomb-making.
Some soldiers have told the AP that Boko Haram has infiltrated Nigeria's security forces and some fight with the army by day and with the extremists by night.
Usman spoke at a news conference where he also reported that in recent days the military has killed 35 extremists and rescued about 300 civilians held by Boko Haram.
Boko Haram pledged allegiance to IS last year. IS propaganda has urged militants who cannot reach Iraq or Syria to go to Africa and fight in Libya or join Boko Haram, but there has been no evidence of IS fighters in Nigeria.
Nigeria's President Muhammadu Buhari declared in December that Nigeria's military has "technically" won the war against Boko Haram, forcing the militants from towns and villages across a swath of the northeast where they had declared an Islamic caliphate.