What week of pregnancy is safe to have the baby?

A baby is counted as 'viable' (able to survive) from 24 weeks of pregnancy but I would not call that safe. 33% of babies born at 24 weeks, 19.9% at 23 weeks, and 9.1% at 22 weeks live long enough to be discharged from hospital. Not surviving but being discharged. So only a third survives from 24 weeks and usually with damages. It's in those last weeks the lungs are developing so I would say week 38 when you have gone the whole pregnancy is the safest. A few weeks before that can also be safe, it depends on the fetus condition and development.