Bacteria exist on the surface of all eggs. Egg shells are porous, however there is a protective layer deposited around the shell of an egg when laid (which is why eggs can look wet when they are ‘just laid’). This is called the ‘bloom’ and it is natures way of stopping bacteria from entering the egg through the pores.
If eggs are washed, the ‘bloom’ is removed which is why it’s best not to wash eggs before storing them.
During incubation or warm weather, bacteria multiply and can sometimes get through the shell and multiply within the egg. If you candle the egg, it will often have dark, irregular patches and if opened (hold your nose) will have gone bad as you can see in the photo.
Nest box hygiene is very important as mucky eggs increase the risk of bacteria getting inside an egg making it far more likely for a hatching egg to go bad, or if the egg is for eating for us to pick up illnesses such as Salmonella. Hens should not be allowed to sleep in nest boxes at night, otherwise they will soil them. This can be discouraged by making perches higher than nest boxes and blocking them off in the late afternoon before they go to roost.