The planets in our solar system formed from the solar nebula of gas and dust that surrounded our infant Sun. The material in this nebula was spinning; as the planets formed from this material, they, too, were spinning.
Objects in motion will stay in motion unless an outside force acts on them. In most everyday applications on Earth, friction counteracts motion by slowing things down, so energy must be added to keep an object moving (or spinning). Our planet doesn’t slow down much simply because there is almost nothing stopping it from continuing to spin.
But there are factors slowing it down, as well as speeding it up. The collision that formed the Moon added rotational energy to the planet, making Earth’s day only about five hours long. Over time, tides raised on Earth by gravitational interactions with the Moon and, to a much lesser extent, the Sun, have slowed our planet’s rotation to the 24-hour day we now experience. Current measurements show the effects of the Sun and Moon are slowing Earth’s rotation at a rate of about 2 milliseconds every 100 years.