There are 1,594 people in Welsh hospitals who are fit to leave but remain there because of care or assessment delays, figures for the last year show.
That is the equivalent of the University Hospital of Wales in Cardiff and Glan Clwyd Hospital, Denbighshire, being full of patients who do not need to be there.
The approximate cost is £478,200 a day or £14.3m a month, according to BBC analysis.
The Welsh government said it provides £146m a year to help health and care organisations work better together.
Figures on the numbers facing delayed discharges are published monthly, but the BBC submitted Freedom of Information (FOI) requests to better understand how long these delays are.
The average delay for patients to leave hospital was five weeks across Wales, the requests found.
The BBC also asked health boards for examples of the longest waits patients who were otherwise fit to leave hospital faced, with the longest being in Cardiff and Vale where one person had to wait 569 days before they were able to leave.
Keeping patients in hospital longer than necessary can be detrimental to their health and wellbeing, while prolonged stays can mean an increased risk of hospital-acquired infections. It can also mean patients need more support once they leave hospital.
The Welsh NHS Confederation said a hospital bed costs £500 a night. For an older person who is medically fit to leave it costs less - an estimated £300.
Using the figure of 1,594 mostly elderly people medically fit for discharge per month, it costs an average of around £478,200 per night.
Delays were mainly due to patients waiting for assessments, a care home placement or suitable home care.
Care in the community is provided by councils but patients need to be assessed by NHS and social services before they can leave hospital.
The Welsh Local Government Association said councils are under pressure, and without increased investment the sustainability of social services was at risk.
In Carmarthenshire a not-for-profit company owned by the council aims to reduce the number of people staying longer in hospital than necessary - known as delayed transfers of care.
Delta Wellbeing services include the "Blue Army", a team of people whose aim is to prevent admission and reduce delayed discharges.
Jane Tremlett, from Carmarthenshire council, said on average patients are discharged five days earlier than they would otherwise be.
“The Blue Army work with clinicians and ward staff. They do assessments on the ward with the patient and get them out of hospital as quickly and as safely as possible,” she said.
Carla Dix, head of business development and partnerships at Delta Wellbeing, said medically trained staff responded to urgent calls from clients.
"We’re able to get those who have suffered a non-injurious fall off the floor in under 45 minutes… invariably stopping an admittance into hospital.
“We’re stopping people coming in [to hospital] and then pulling people out as quickly as we can and making sure they can be at home when they need to be,” she said.
Of the 400 to 500 callouts they received a month, only 6% were escalated to emergency services, she said.
The British Medical Association described the issue as a “national emergency” that is reflected in “gruelling accounts” from its members who had spoken about “treating patients in corridors, on chairs and in the back of ambulances”.
“Alarmingly, these circumstances are putting patients across Wales at significant risk, the longer they wait for timely care in hospital or at home waiting for an ambulance the longer their condition deteriorates,” said Dr Phil White, deputy chair of BMA’s Welsh council.
Plaid Cymru called for carers to be paid more to improve recruitment in order to ensure more care was available in the community.
Mabon ap Gwynfor, the party's health and care spokesperson, said the number of delayed transfers of care was "completely unsustainable", saying the Welsh government's priorities were wrong.
Sam Rowlands of the Welsh Conservatives also accused the Welsh government of having “the wrong priorities”.
He criticised the decision to spend money on increasing the number of Senedd members “when we could be investing in more doctors and nurses”, which he said would “save many millions” in the long run.
The Welsh government said it was committed to improving the process for people leaving hospital and understood the impact on patients and their families.
"Community services are being increased so people can live and age well at home, avoid unnecessary admission to hospital and return home quickly where hospital care was necessary," a spokesperson said.
The spokesperson said the Welsh government was providing £146m a year "to help health and care organisations work better together", and said its national Care Action Committee was working to identify what can be done "to support the discharge process, particularly in the lead up to winter".