The government is paying more than £4m each year in compensation to people who were held unlawfully in immigration detention centres, figures show.
The centres hold people the government is trying to deport, including failed asylum seekers and foreign prisoners.
A BBC Freedom of Information request found the government paid £4m in 2014-15, and between £4-5m in each of the previous three years, totalling £18m.
The Home Office said detention was part of a firm but fair immigration system.
About 30,000 people pass through the UK's detention centres every year, costing approximately £35,000 a year per detainee.
If judges determine the government has detained someone unlawfully, it must pay compensation.
The Freedom of Information request submitted by the Victoria Derbyshire programme found the government paid in total:
- £4,461,344 in 2011-12
- £5,017,971 in 2012-13
- £4,775,000 in 2013-14
- £4,000,000 in 2014-15
Conservative MP Tim Loughton, a member of the Home Affairs Committee, said that last year 60% of the 32,000 people who went through the centres went back into the community, which suggested the system was not working.
"These are not prisons, they are places purely to hold people who might be at risk of absconding between getting hold of them and putting them on a plane out of the country.
"I think many taxpayers would be greatly annoyed and offended that their money is going not only to look after some of these people who should not be in these detention centres, but we're actually having to pay out compensation because the courts have deemed that they've been detained wrongly as well."
A separate Freedom of Information request from the charity Citizens UK found that between 2012 and 2015, the Home Office paid up to £155,000 to individuals wrongfully detained.
Jerome Phelps, director of Detention Action, a charity which supports people held in detention centres, said the UK was the only country in Europe that had no time limit on detention.
"Immigration detention is lawful in certain circumstances where the Home Office is intending to deport someone and there's a reasonable prospect of that taking place.
"But what we're seeing is people being detained for months, often for years, long after it becomes apparent that there's no prospect of their deportation actually taking place," he said.
Last month, during a debate on the proposed Immigration Bill, peers in the House of Lords voted that detention should be limited to 28 days, except when a court decides otherwise - defeating the government.
The government had argued most of those detained were either foreign criminals or had previously broken immigration rules.
Opponents insisted the limit was needed because detaining people indefinitely had a negative impact on their mental health.
Recent inspections have found detainees being held for more than a year, and in two cases for as long as five years, at Verne IRC in Dorset and Harmondsworth IRC in west London - which is Europe's largest.
A Home Office spokeswoman said: "Detention is an important part of a firm but fair immigration system, helping to ensure that those with no right to remain in the UK are returned to their home country if they will not leave voluntarily.
"Decisions to detain individuals are reviewed regularly to ensure they remain justified and reasonable and, if necessary, they can be challenged through the courts.
"We are committed to treating all detainees with dignity and respect and take the welfare of detainees very seriously.
"Following an independent review by Stephen Shaw, commissioned by the home secretary, the government is taking forward three key reforms - introducing a new "adult at risk" concept into decision making on immigration detention, publishing a mental health action plan and implementing a new approach to the case management of all those detained.
"We expect these reforms - and broader changes in legislation, policy and operational approaches - to lead to a reduction in the number of detainees and the length of time they spend in detention before removal."
Watch the Victoria Derbyshire programme on weekdays between 09:00 and 11:00 on BBC Two and the BBC News Channel.
Photographs taken by Nana Varveropoulou as part of her project called No Man's Land, sponsored by Counterpoints Arts and Arts Council England.
Additional Research by Sam Bright.