37/38 weeks vs 40?

Why is it that 37-38 weeks are considered full term, but it’s better for the baby to stay in until 40 weeks?