An excellent question!! Solid ice and liquid water are the phases of the same substance. The density of the solid phase is generally larger than that of its liquid counterpart. However, in the case of water, ice is less dense compared to water and this is the reason why ice floats. At the molecular level, liquid water is made up of hydrogen bonds that push the molecules further apart when the water crystallizes into ice. This causes the ice to become less dense and hence, this is why an iceberg can float on water. In nature, this phenomenon helps preserving all the animals living in water from freezing during winter.
I hope this explains the concept. Please let me know if you have any additional questions and I'd be happy to help.