Nigeria is to set free about half of all prisoners to reduce overcrowding.
Some 65% of those in Nigeria's prisons have not been convicted
Up to 25,000 people, including the sick, the elderly and those with HIV will be freed, said Justice Minister Bayo Ojo.
Those who have been awaiting trial for longer than the sentences they face and those whose case files have been lost by the authorities will also benefit.
Correspondents say many people wait up to 10 years, often in awful conditions, for their case to come to trial.
Human rights groups say death rates are unacceptably high for inmates who endure overcrowded and unsanitary conditions.
"The issue of awaiting-trial inmates has become an endemic problem in Nigeria... The conditions of the prisons are just too terrible. The conditions negate the essence of prison which is to reform," Mr Ojo said.
There are currently some 40,444 inmates held in 227 prisons across Nigeria.
Some 65% of these are awaiting trial.
The government will build six "half-way houses" to provide those being freed with education and training, Mr Ojo said.
"By the time the process is completed, we hope to have reduced the inmates to between 15,000 and 20,000," Mr Ojo told a news conference.
To facilitate the releases, a new chief prison inspector is also set to be named, with responsibility for improving prison conditions.