Floating an egg is not an accurate test for whether an egg has spoiled, but it can tell you more about the age of the egg. Eggs naturally develop an air cell between the egg white and the shell. As the egg ages, the contents of the egg contract, causing the air cell to grow larger. If the air cell grows large enough, the egg can float in water. So, an egg that floats might be older than one that sinks, but that does not mean it is spoiled.
Some eggs have a larger egg cell than others to begin with, so this test is not precise. The best way to tell whether an egg is bad is to break it in a bowl separate from other ingredients. If the egg has appears off color, or has a rotten smell, then do not consume it.