Home Secretary Theresa May has won a human rights fight over where foreign criminals can be held while they await deportation after serving prison sentences.
It came after an Algerian illegal immigrant convicted of theft complained that he was unfairly held in jail after completing his term.
Fouad Idira said that he should have been kept in an immigration centre and argued that holding him inside a prison was a breach of his right to liberty under Article 5 of the European Convention on Human Rights.
But a senior judge concluded that immigration detention in prison rather than in an immigration removal centre was not a breach of the right to liberty.
Lord Dyson, the Master of the Rolls, headed a three-strong panel which analysed the issues at a Court of Appeal hearing in London. The two other judges on the panel agreed with him.
"For some vulnerable detainees, detention in prison may be seriously inappropriate," Lord Dyson told the court.
"But it must depend on the vulnerability of the detainee and the nature of the prison conditions."
"A prison is not an inappropriate place in which to detain an able-bodied man who is due to be removed from the country on the grounds that his criminality makes his departure conducive to the public good, and whom the public interest requires to be detained while that is arranged."