Soldiers opened fire on the woman when she refused to be searched as she approached the barracks in Bolari, in Gombe state, detonating the explosives belt she was wearing, according to eyewitness accounts.
The woman, who was wearing a hijab, was killed instantly, witnesses said. "The woman refused to stop and continued to advance towards the military guards at the gates despite repeated orders from them to stop at a distance," said Shuaibu Nasir, who lives near the gates of the barracks.
"The soldiers opened fire on the woman who quickened her pace towards them and as they fired shots at her she exploded with a loud sound that shook our buildings," Nasir said.
Nigeria's northeastern Gombe state has been the scene of several attacks by the Islamist group Boko Haram in recent months, and the same barracks were targeted in July.
Wednesday's blast prompted policemen to fire warning shots in the air, causing panic among residents, Nasir said. Another resident, Ahmed Baballe, said the would-be bomber was "blown to pieces" by the impact of the explosion.
"The soldiers didn't take chances with the woman and opened fire when she showed no sign of stopping to be searched," Baballe said.
Northeast Nigeria has been continually rocked by attacks mounted by Boko Haram militants, increasingly using female suicide bombers.
The extremist group, whose name roughly means "Western education is forbidden", have killed thousands since it began a deadly insurgency in northern Nigeria in 2009.
Experts have cast doubt on Nigeria's ability to hold planned national elections in February, because of rising unrest in parts of the northeast.
Hours earlier on Wednesday, witnesses said that seven people were killed when a bus exploded in a village close to Potiskum, the commercial capital of northern Yobe state.
"The bus went up in flames from multiple blasts that killed all seven men inside," said Hambali Baidu, a resident of Maiduwa village, which lies some 60 kilometres from the city.
No official confirmation of the death toll has been given. "We heard a series of explosions from the bus which went flying into the air in flames," said Usman Haruna, another resident.