Their release comes just one day after a separate raid on a school in Nigeria's Zamfara state, where a gang seized more than 300 girls.
Twenty-seven students, three staff and 12 members of their families were abducted when armed men stormed the Government Science secondary school in the Kagara district of Niger state on 17 February.
The attack overwhelmed the school's security and one boy was killed.
Governor Abubakar Sani Bello tweeted: "The Abducted Students, Staff and Relatives of Government Science Collage Kagara have regained their freedom and have been received by the Niger State Government.”
The recent attacks have raised concerns about armed gangs and Islamist insurgents. The Jihadist group Boko Haram and a branch of Islamic State are both known to carry out abductions in Nigeria's northeast.
Kidnappings for ransom by armed groups, many of whom carry guns and ride motorcycles, are common across many northern Nigerian states.
President Muhammadu Buhari, a retired general and former military ruler, has faced criticism in recent months over high profile attacks by the gangs known locally as "bandits".
He replaced his long-standing military chiefs this month amid worsening violence in Nigeria.
Violence and insecurity have compounded the economic challenges faced by citizens in Africa's most populous country and top oil exporter, which is struggling to cope with a fall in revenues due to a slump in crude prices in addition to the impact of the Covid pandemic.
Join our new commenting forum
Join thought-provoking conversations, follow other Independent readers and see their replies