Something floats because it is less dense than whatever it is floating on. A denser substance displaces something less dense, responds more strongly to gravity, and sinks right through the less dense substance like a basketball through a hoop. Generally gaseous forms of a substance are less dense than liquids, because their atoms are spread more thinly through their volume. Liquids are usually less dense than solid forms of a given substance because, again, they have fewer atoms in a given volume. Mass per volume is the measure of density, and substances with fewer atoms per volume have less mass as a rule. This explains why air floats above land and sea, and why the oceans rest above the seabed. Iron is more "massive" (more dense) than water, and sinks right through it, unless you call it a ship, hollow it out and fill it with a gas (air), thus decreasing its overall density so that it floats.
So why does a piece of ice float? It's the solid form of water, so it ought to sink right through the liquid form, but it doesn't. Instead, it sits on top, capping lakes and streams in winter, and floating in the polar oceans. This seems perfectly normal because we have experienced it all our lives, at least until we think about it.
As a matter of fact, ice is one of the very few substances known in nature that expand when they freeze. Because it expands, ice has less mass per unit of volume, and its density decreases. When it becomes less dense than the water it froze out of, it floats on top.
The reason it expands when it becomes solid (freezes) is the crystalline structure given to ice by hydrogen bonds. Water, of course, is H2O, meaning there are two hydrogen atoms for every oxygen atom in the water molecule. These atoms are joined together in a molecule because their charges complement one another. That is, the atoms, the relatively massive oxygen and the much smaller hydrogen, share electrons in such a way that their electron shells complete each other to form the unit that is a molecule of water. But the large oxygen molecule still has sites on it that could, in the right circumstances, form more bonds. These would be relatively weak bonds, formed with other hydrogen atoms sticking off other water molecules. But the water molecules in a liquid have lots of energy, they move around, and the hydrogen bonds do not hold them. If the water is cooled down though, the molecules lose energy, and the weak hydrogen bonds can take hold. They hold the water molecules in a crystalline lattice, in which the oxygen atoms are actually held farther apart from each other than they would be in the liquid form. There is more space between them, so the ice is less dense.
At normal atmospheric pressure and temperatures of zero degrees Celsius or below, the hydrogen bonds in water hold its atoms far enough apart that ordinary ice takes up about 9% more volume than it did as ice. So it is less dense, and it floats.