Thousands of people have been wrongly identified as liable for the bedroom tax, including some who now face eviction or have been forced to move to a smaller property, as a result of an error by Department of Work and Pensions.

Housing experts believe as many as 40,000 people could be affected by the mistake. The DWP says it believes only a "small number" of tenants are affected, which it estimates number 5,000.

All could be eligible for refunds worth on average at least £640 per claimant and millions in aggregate.

The error affects working age tenants in social housing who have occupied the same home continuously since 1996. An oversight by the Department for Work and Pensions (DWP) when drafting the legislation means that the housing benefit regulations dating from 1996 were not updated when the coalition legislated for the bedroom tax.

Chris Bryant MP, Labour's shadow minister for welfare reform, said: "This is the latest example of the chaos and confusion within the Department of Work and Pensions under Iain Duncan Smith. Rather than closing loopholes in the policy, the government should scrap their hated bedroom tax. If they don't, the next Labour government will." A spokesperson for the DWP said the regulations would be amended to close the loophole, although it is not clear how this will be done.

The bedroom tax affects 660,000 housing benefit claimants living in social housing. The policy imposes an average penalty of between £14 and £22 a week on working-age tenants deemed to have more bedrooms than they need.

Joe Halewood, an independent housing consultant, says that the estimate that 40,000 people were affected was based on the scaling up nationally of figures collected by Exeter City council, which has identified 31 of its housing tenants – 4.5% of those affected by the bedroom tax in the city – as wrongly held liable. .

Halewood told the Guardian's housing network website: "Forty thousand is actually a conservative estimate. You're looking at one in 25 of housing benefit claimants being affected."

Peter Delamothe, a housing benefit consultant at HBinfo, said he had spoken to a council that had already identified 250 tenants wrongly ruled liable for the bedroom tax: "This is a shambles caused by the DWP failing to understand the significance of their own legislation".

Another council, which did not want to be named, said its initial inquiries suggested 15% of its tenants affected by the bedroom tax could be exempt and would qualify for a refund.

The Exeter tenants received exemption notices in December, after a local tribunal discovered the loophole. News of the decision spread over the Christmas and new year period as local campaigners raised the issue on social media, and it is understood that several individual appeals have been launched around the country.

It is believed that some tenants who may now be deemed exempt will have received hundreds of pounds in emergency discretionary housing payments (DHPs) since April to help them cope with the shortfall in their income caused by the bedroom tax. They will have their housing benefit refunded, but will not be obliged to repay the DHP cash, which may result in some actually gaining hundreds of pounds in cash.

Some councils have assigned staff to assess how many households in their area are affected, but there are concerns that most will not have kept housing records dating back to 1996. Some are understood to have legitimately destroyed older files under data protection rules.

In effect this may mean that councils will be forced to judge many exemption claims on the "balance of probability". The process of investigating individual claims could take weeks or months, according to one housing sector insider.

The DWP error could also lead to hundreds of applications to the local government ombudsman as tenants seek redress for being wrongly made liable for the bedroom tax.

Theo Blackwell, the cabinet member for finance at Camden council said: "While good news for those families, it is an administrative nightmare as we have to find those continuously in receipt of housing benefit going back 18 years, when we – like most councils – have changed systems largely from a paper-based one to new IT systems. This is more evidence of how the bedroom tax policy was rushed and ill-conceived."

Giles Peaker, a solicitor at Anthony Gold who blogs about housing law at the Nearly Legal website, said: "It wouldn't be a surprise if regulations accidentally failed to amend or repeal some previous regulations. It happens quite often when the relevant law is labyrinthine. If I were a housing benefit recipient in the relevant situation, I would certainly appeal the bedroom tax deduction on these grounds."