The families of three British residents held in Guantanamo Bay since 2002 have failed in a bid to force the government to request their return to the UK.
The government says it cannot give diplomatic protection to non-citizens
Appeal court judges rejected claims the men should be treated as UK citizens.
Libyan-born Omar Deghayes, 37, from Brighton, Jordanian Jamil el-Banna and Iraqi Bisher al-Rawi, both from London, all have leave to remain in the UK.
The ruling comes after the High Court also refused to quash the government's decision not to request their return.
Lawyers for the families have argued the detainees have been tortured and should be released from the US-run camp in Cuba.
But the Foreign Office says it cannot provide diplomatic protection to non-citizens.
The Court of Appeal judges were asked to declare that the men, although foreign nationals, were long-term UK residents entitled to help similar to that received by British citizens freed from Guantanamo in 2004 and 2005.
But Lord Justice Laws, announcing that the court had dismissed the three appeals, said the government's decision did not contravene human rights or race relations laws.
Rabinder Singh QC, acting for the families, had told the Appeal Court none of the detainees had any "meaningful ties" to any other country, and that Mr el-Banna and Mr Deghayes, as refugees, had been accepted by the UK as being at risk of persecution or torture.
He said the government's continuing refusal to act was contrary to the Race Relations Act and was breaching the rights of the men's' families, who are British citizens.
Mr Singh said each man had been subjected to arbitrary detention without trial and that their plight was causing their families intense suffering.
Lord Justice Laws accepted the premise that the detainees had been subjected at least to inhuman and degrading treatment.
But he said there had been no discrimination against the detainees either under human rights or race relations laws.
Lord Justice Laws said the families' argument that their human rights were being infringed because of their separation from their husbands and fathers also failed.
He said: "This suffering is the consequence of the actions of a foreign sovereign state for which the United Kingdom bears no responsibility under the European Convention on Human Rights or the Human Rights Act."
Human rights group Amnesty International said the court had missed an opportunity to "send a clear message to the government that it must fulfil its responsibilities towards all Guantanamo detainees, regardless of whether they are UK citizens or residents".
Europe and Central Asia director Nicola Duckworth said: "The failure of the UK authorities to make representations on behalf of all UK residents held at Guantanamo Bay is inconsistent with the strong condemnation by a number of government members of the detention centre for its human rights abuses."
Mr al-Rawi and his friend Mr el-Banna were arrested in November 2002 during a business trip to Gambia, on suspicion of having links to terrorism. Mr Deghayes was arrested in Pakistan in 2002 and accused of committing terrorist acts against the US.
He fled Libya for the UK in the 1980s after his father was assassinated and applied for British citizenship.
The men's relatives, many of whom are British, deny the trio have any links to terrorism.