That's an interesting question. Scientists at UCSB have been studying how abalone shell forms and what makes it so much stronger than cement. They call their research 'biomineralization' - 'bio' for biology - learning about plants and animals - and 'mineralization' for how minerals are formed.
The egg is made inside the hen, so the hen's body must somehow deposit the eggshell. And there is a membrane just inside the egg shell - maybe you have noticed.
It looks like the egg shell is made in the day before the egg is laid, and the egg is moving through a tube in the chicken while the egg shell is being made. The shell has proteins that are important for making the shell strong. Shells have lots of calcium, like bones.
I'm a professor at UCSB. I study how organisms develop and although most of my research is on sea urchins and sea stars, I love to think about eggs in general and how they "work." Just think -- you (and I) used to be one cell (an egg) about the size of a dust speck. Now look at you!
Scientists have been interested in this question for a long time and we know quite a bit about it. One reason we know so much about it is that a terrible thing started happening to birds' eggs when a chemical called DDT was used to control mosquitoes. You can ask your teacher or your parents about this pesticide (which is not used in the USA anymore, but is used in many other countries). DDT is a great insecticide (do you know what major human disease can be carried by mosquitoes, especially in warm climates?) but it also causes the eggshells of birds to become very fragile and thus, it affects not only insects but the birds (the eggs break in the nest). Birds such as peregrine falcons almost became extinct because of DDT use. Anyway, because of this observation, scientists studied in great detail how the eggshells were made. Also, chicken farmers are interested in having their hens lay eggs quickly and in having those eggs have hard shells (so they don't crack during collection and shipping!). So, if we can understand how shells are made, we can make sure that the chickens get the proper nutrients to make good shells and we hopefully can avoid using future pesticides that might affect birds and other egg-layers.
Here is the basics: In the bird (or reptile), the developing egg (oocyte) enters into a specialized area of the reproductive tract called the "isthmus." These special cells secrete two soft membranes that surround the egg. Crack open a chicken egg -- see the whitish membranes that are between the hard shell and the egg itself? That's them! If you hard boil an egg, you can sometimes peel away the membrane.
Then the egg moves into another area called the "shell gland." The cells in this gland secrete the actual shell material, which covers the egg. In birds, the shell usually hardens ("calcifies") while in reptiles (like turtles and snakes), the "shell" is more leathery. After the shell material coats the egg, the egg passes through the rest of the reproductive tract and is "laid." In chickens, the process of making the hard shell takes about 20 hours! And that is why a hen lays only 1 egg/day.
DDT interferes with the ability of the shell gland to make the proper shell material, so the shell, although it is there, is really fragile (breaks easily).
Next time you eat an egg, think of all of the hard work and energy the hen put into laying her egg! And keep asking questions!