Kiaya, how big do you plan to make them? You’ll often see a 12” x 12” minimum for full-sized hens, which will work, but I like them bigger. I made mine 16” x 16” x 16”. I often have 2 or even 3 sharing a nest at one time. They can still do that in a smaller nest, but they might wind up laying on top of each other.
Another reason I like them a bit bigger is that I let broodies hatch in those nests. I have used smaller nests and I find a chick is a lot more likely to fall from the nest if the nest is small. Chicks often climb on top of a hen and if she is too close to the edge of the nest, they can fall off. A high lip across the front can help with that too, plus it keeps them from scratching out the bedding and eggs when they are adjusting the nest just the way they like it.
You could build a community nest box. There are different sizes but think of a box maybe 2’ deep and 4’ to 5’ long with openings on each end. Hinge the top so you can open it to get the eggs. These don’t work really great for broody hens, but just two of these could easily handle your 40 hens as far as laying eggs. There are lots of different ways to do these things.
That ratio of 4 to 1 will work, but that’s geared more toward smaller flocks. As Picco said, they all tend to lay in one or two anyway. With larger flocks like your 40, you could go with a 5 to 1 ratio instead, which means 8 would be plenty. I’m not going to criticize anyone for going more because too many is better than not enough, but in your case, I really don’t think it is necessary. Of course, that gives you room to expand your flock if you want to. I do like some flexibility.
20 hens is getting in that nebulous area where 4 to 1 will work but 5 to 1 will probably work. Four nests would probably work but five gives you that sense of security. Most of them will still use the same one or two.