I place the egg in a glass of water.
If it floats, it is bad. If it stands up, use it for cooking (e.g. a hard boiled egg but not soft), it's getting old. If it sinks, you're safe.
The outer shell of an egg has two membranes under it. When an egg is laid, it is warm and starts cooling which contracts the inner part of the egg more than the shell and pulls the two membranes apart. As a result, air gets trapped in between the membranes (there is not enough air initially for it to float).
As this egg gets older, air is taken in (due to slightly higher pressure from the contractions) through pores in the egg. Eventually, bacteria will get in too. When the egg has enough air to float, it's probably gone bad with the bacteria.
Image © Tim, 2014