Prison overcrowding is at a critical level because of the government's sentencing policy, the Lord Chief Justice of England and Wales has said.
Lord Phillips called for more community punishments
Speaking at a Howard League for Penal Reform event, Lord Phillips said UK jails were "full to capacity", adding: "We simply cannot go on like this."
He said legislation forcing judges to give longer terms had worsened things.
Justice Secretary Jack Straw welcomed his comments, while the Tories said they showed the system could not cope.
The Ministry of Justice has said more prison places are being built to offset overcrowding.
Lord Phillips told the audience that between 200 and 300 prisoners a night were being held in police cells in England and Wales because prisons were full.
Jails were forced to close their doors to new admissions, with cells designed for one prisoner having to accommodate two, he added.
He said the problem was that consequences of the 2003 Criminal Justice Act - which led to longer sentences for murder and other serious crimes - had not been foreseen by ministers and MPs.
"Unless Parliament is prepared to provide whatever resources are necessary to give effect to the sentences that judges choose, in their discretion, to impose, Parliament must re-examine the legislative framework for sentencing.
"I do not believe that these simple propositions have been fully appreciated by those responsible for formulating criminal policy."
He called for more emphasis on fines and community rehabilitation as well as increased effort to tackle family breakdown.
"If you decide to lock up one man for a minimum term of 30 years, you are investing £1m or more in punishing him," Lord Phillips said.
"That sum could pay for quite a few surgical operations or for a lot of remedial training in some of the schools where the staff are struggling to cope with the problems of trying to teach children who cannot even understand English. "
Nick Herbert, the Conservative justice spokesman, said the government had not paid attention to prison levels when setting the sentencing framework.
He added: "We are now paying the price with grossly overcrowded prisons that do not rehabilitate offenders, rising reconviction rates and panic early release measures."
Lib Dem justice spokesman David Heath said it was "completely unacceptable" for judges to feel constrained about putting dangerous criminals in prison.
"The answer must be to take out of the prison system those who shouldn't be there in the first place," he said.
"People with mental illness or drug addictions should be getting proper treatment."
The Howard League for Penal Reform's Andrew Neilson said Lord Phillips' speech had been a coded attack on the policies of successive governments.
Mr Neilson told BBC News: "Suddenly, he said that the consequences of sentencing policy have not been fully appreciated by those responsible for formulating criminal justice policy - which is top judge code for criticising the government."
He said the league agreed there needed to be more emphasis on community sentences "if they're to work effectively, as they can do".
"Politicians need to be prepared to defend community sentences to the media and the public in general and build confidence in them," he added.
Justice Secretary Jack Straw said: "I welcome this significant speech.
"It makes an important contribution to a matter of great public interest."
The Ministry of Justice says that, since Labour came into power in 1997, there are 20,000 more prison places - 3,100 of which were built in the last two years.
Earlier this year, John Reid, the then home secretary, announced proposals to build two new prisons - in Maghull, near Liverpool, and next to Belmarsh prison in Woolwich, south-east London - to provide an additional 1,300 spaces.
They form part of plans to provide an extra 8,000 cells over five years.