How a chicken makes its egg
During their laying lifetime, hens will produce about eight times their bodyweight in eggs.
These come from a few thousand specialized germ cells in the chicken’s ovary. They are the small pinhead-sized white specks that can be seen riding on the top of the yolk. Everything else is life-support for this cell.
On reaching laying age, one by one and staggered in time, these cells start to accumulate a yellow yolk. This is synthesised in the chicken’s liver, and its colour depends on what the chicken is eating at the time. Full yolk production takes ~10 weeks. From this point, it takes about 24 additional hours to produce the complete egg.
When ready, the yolk passes along the oviduct, which can be almost 1m in length. At entry, it may be fertilised, depending upon recent hen-rooster social activities. Thereafter, for the next 2–3 hours, egg white protein is secreted around the yolk in layers. During the first layer, the egg passes through spiral grooves in the oviduct wall that twist the yolk and white to form the two elastic cords that will anchor the yolk to the shell and keep it suspended in the white. After that, egg white is deposited in two forms — thick and thin (which becomes relevant when poaching eggs).
After the white is deposited, the egg moves on and spends about an hour being enclosed in two concentric anti-microbial membranes that are fused to each other everywhere except at what will become the blunt(er) end of the egg.
The egg then spends the next 20 hours or so in the hen’s uteris, where for the first 5 hours water is pumped into the egg to plump it to full volume. After this, the uterine lining secretes calcium carbonate for the eggshell (~14 hours), which is porous to allow any developing embryo to breathe.
Finally, the egg progresses to the final stage where a thin cuticle layer is applied. This gives the egg its characteristic colour and pattern (which has nothing to do with the diet of the hen). The cuticle layer also plugs the air pores in the shell to minimize water loss and bacterial invasion. Later, during the development of the chick, this layer breaks down, exposing the porous shell and allowing air back into the egg for the chick.
After the egg is laid, it cools down and its contents shrink slightly, thereby pulling the inner anti-microbial membrane away from the outer membrane at the blunt end and creating an air space in the egg for the chick.
I couldn’t have made this up if I tried.
Further reading: H. McGee, On Food and Cooking.