The fire, the country's most deadly since 47 perished in a firework factory disaster in 2017, broke out at 1.45 a.m. local time in a Tangerang Prison block, said Indonesian law and human rights minister Yasonna Laoly, after visiting the scene.
"We're working together with relevant authorities to look into the causes of the fire and of course formulating prevention strategies so that severe catastrophes like this won't happen again," the minister said in a statement.
The minister said two of the dead were foreign nationals, one each from South Africa and Portugal, and confirmed the prison was operating in overcapacity when the fire broke out.
Cells were locked at the time, the minister said, but with the fire raging uncontrollably, "some rooms couldn't be opened."
On Wednesday morning local TV showed footage of flames engulfing the detention facility, and later, the building's charred remains as victims were pulled from the scene in orange body bags.
Prisons in Indonesia are notoriously overcrowded, with experts saying the phenomenon is partly due to the emphasis on incarceration rather than rehabilitation of those convicted of drug-related offenses under the country's strict narcotics laws.