The legal ban on smoking in public places does not apply to state prisons in England and Wales, the Court of Appeal has ruled.
Three judges allowed a government appeal against a High Court ruling that a ban introduced in 2007 covered all public places and all workplaces.
The government says it means a ban can be rolled out gradually "in a safe and secure way" rather than rushed through.
An inmate who wanted quicker implementation had brought the case.
Smoking is currently allowed only in prison cells and exercise yards.
The government eventually intends to make all 136 prisons in England and Wales entirely smoke-free to reduce health risks to staff and inmates.
BBC correspondent Daniel Boettcher said the smoking ban had already begun in prisons in Wales.
He said those who had wanted this to happen a great deal quicker took the matter to court, arguing that the 2007 ban should by now be enforced across the prison estate.
That was rejected by the Court of Appeal after government lawyers warned that a "particularly vigorous" ban could cause discipline problems and risk the safety of staff and inmates.
That warning has been echoed by the Prison Governors Association, which is in favour of a ban, but has raised concerns about it potentially leading to instability in jails, given about 80% of inmates currently smoke.
A Prison Service spokesman said: "The result of this appeal means we are able to roll out smoke free prisons in a safe and secure way.
"Our careful approach will ensure staff and prisoners are no longer exposed to second-hand smoke, while not compromising the safety and security of our prisons."