It takes Earth 23 hours, 56 minutes and 4.091 seconds to completely rotate on its axis compared to the background stars. This amount of time is known as a sidereal day.
Earth rotates from west to east, which is why the Sun rises in the east and sets in the west. Earth's rotation is also slowing slightly with time, meaning that days were shorter in the past. This is due to the effect of the Moon on Earth's rotation. Atomic clocks show that a day is now about 1.7 milliseconds longer than it was a century ago. Although it takes 23 hours, 56 minutes and 4.091 seconds to rotate compared to the background stars, it takes 24 hours for the Sun to return to the same spot in the sky. This is because while Earth is spinning around its axis, it is also spinning around the Sun.