Junior doctors have won a court case against a hospital trust over rest breaks which could have far-reaching implications for the NHS.
The 21 doctors said Derby Hospitals NHS Foundation Trust failed to make sure they either took proper breaks or were paid extra for working.
Lord Justice Bean said the trust's method of calculating breaks was "irrational" and a breach of contract.
It is estimated the trainees could be owed £250,000 in unpaid salary.
At the Court of Appeal, Lord Justice Bean said the wider cost to the NHS is "potentially substantial".
Lawyers for Health Secretary Matt Hancock previously told the court the financial implications of the appeal succeeding would be "considerable".
Junior doctors across the NHS should get a 30-minute break every four hours they work or be paid double for the time.
Lord Justice Bean said Derby Hospitals' method was flawed because it used data from advance rotas and not from actual recordings of shift patterns.
Giving the ruling he said: "The defendant's method of calculation is both in breach of the contract on its proper interpretation and also irrational."
Dr Sarah Hallett, who trained at the Royal Derby Hospital for eight months with 20 other junior doctors in 2013, led the appeal after she lost a High Court challenge last April.
She tweeted the ruling was a "bittersweet victory".
Over 4 years after starting to look into my case, this is something of a bittersweet victory today. It should not have needed to escalate to this level to confirm the importance of accurately assessing if junior doctors are getting breaks. https://t.co/RpJU6sy2Lb— Sarah Hallett (@DrSarahHal) July 30, 2019
The British Medical Association, which backed the appeal, said the judgement was a "significant victory".
It added: "In overturning last year's ruling, the Court of Appeal has established a binding precedent in England and Wales."
A Department of Health said it was "disappointed" and will support Derby Hospitals' next steps.