A group of 82 girls held captive for three years by Islamist militants have met the Nigerian president in the capital Abuja after being released in exchange for several militant commanders.

"I cannot express in a few words how happy I am to welcome our dear girls back to freedom," President Muhammadu Buhari told the girls surrounding him in his residency, a presidency statement said.

"On behalf of all Nigerians, I will like to share my joy with you," he told the girls.

The girls were among a group of 270 schoolgirls kidnapped in April 2014 by the militant group Boko Haram, which has waged an eight-year insurgency to create an Islamist caliphate, killing thousands and forcing more than two million from their homes.

The government secured the release with mediation by the International Committee of the Red Cross.

A military source said three Boko Haram commanders had been freed in an exchange, but declined to give further details.

The military source said the girls had been flown from Banki near the border with Cameroon to Maiduguri and then Abuja, where they first got a medical checkup at a police hospital before being driven in two buses to the presidential villa.

Their meeting with the president apparently took place before they were reunited with their parents and relatives.

In Chibok, the remote town in northeastern Nigeria where the girls were abducted from, families were waiting for names of those freed to be published.

Their release was a boost for Mr Buhari, a former military ruler who made crushing Boko Haram a pillar of his election campaign in 2015.

Mr Buhari has made few public appearances since returning from Britain in March for medical treatment.

"Let me reassure Nigerians, especially relatives and friends of the remaining girls that the Federal Government will spare no effort to see that they and all other Nigerians who have been abducted safely regain their freedom," Mr Buhari said in the statement.

Although the kidnapping of the Chibok girls caught global attention, Boko Haram, which has pledged loyalty to the so-called Islamic State group, has kidnapped thousands of adults and children.

The army has retaken much of the territory initially lost to Boko Haram, but large parts of the northeast, particularly in Borno state, remain under threat from the militants.