The speed of sound depends on the elasticity and density of the medium through which it is traveling. In general, sound travels faster in liquids than in gases and faster in solids than in liquids. The greater the elasticity and the lower the density, the faster sound travels in a medium. The mathematical relationship is speed = (elasticity/density).
The speed of sound in a material, particularly in a gas or liquid, varies with temperature because a change in temperature affects the material's density.