How far do monsters have to be from your bed for you to sleep?

In minecraft pe, somtimes when you try to sleep it gives ytou the "you can't skeep now, there are monsters nearby" message. So exactly how many blocks away to monsters need to be for it to let you sleep? Please don't answer unless you know for sure

According to the minecraft wiki: "you can't sleep if a hostile mob is within 8 blocks of the bed horizontally (along each axis) and 5 blocks vertically"