According to witnesses who escaped, the attackers rounded up students and staff of the school and placed them in a dormitory, then threw explosives inside and opened fire, said Haliru Aliyu of Potiskum General Hospital.
"We received 42 dead bodies of students and other staff of Government Secondary School (in) Mamudo last night. Some of them had gunshot wounds while many of them had burns and ruptured tissues," Aliyu told AFP.
Aliyu said security personnel were combing the bushes around the school in search of wounded students who were believed to have escaped.
"So far six students have been found and are now in the hospital being treated for gunshot wounds," he said.
More From This Section
Mamudo is some five kilometres from Potiskum, the commercial hub of the northeastern state of Yobe, which has been a flashpoint in the Boko Haram insurgency in recent months.
"It was a gory sight. People who went to the hospital and saw the bodies shed tears," he said.
"There were 42 bodies, most of them were students. Some of them had parts of their bodies blown off and badly burnt while others had gunshot wounds."
He said the attack was believed to be a reprisal by Boko Haram for the killing of 22 of the Islamist group's members during a military raid in the town of Dogon Kuka on Thursday.
A senior police officer said the gunmen started "shooting sporadically and subsequently set the students' hostel abaze."
Residents said the latest incident has sparked panic among students in the area and many of them have left their dormitories for home even though schools are still in session in the state.
Mobile phone lines have been cut in much of the northeast since the start of a military offensive targeting Boko Haram on May 15, and access to the area is limited.
Residents of Potiskum and adjoining towns and villages reportedly have to go to Dagauda near Bauchi state to make and receive telephone calls.