It's a combination of up-down (north-south) and east-west motions. The up-down component is simple, that comes from the axial tilt.
The east-west component arises from this: When the Earth is at perihelion (January), the time from solar noon to solar noon is slightly longer, because the Earth is moving faster and farther in its orbit, so it has to rotate a bit more until the same meridian points back at the sun again. At aphelion (July), that's reversed, solar noon to solar noon is slightly shorter.
Put another way: A solar day is more than 360° of rotation relative to distant stars. It's very close to 361°, because the angle between the stars and the sun changes as the Earth advances in its orbit, by about a degree per day. At perihelion in January, it's slightly more yet again, like 361.0002°, and in July, it's 360.9998°; that difference takes a few seconds more or less to rotate. We don't vary our clocks based on that variable solar day duration; instead we fix our daily time intervals and let the sun's apparent position vary east-west slightly relative to that.
The figure-8 shape arises from the relative phase of the two cycles. The maximum velocity for the north-south component occurs at the equinoxes, while the maximum velocity for the east-west component occurs at perihelion/aphelion. On Earth, these occur at different times. Interestingly, for Mars the converse is true; its equinoxes are near its perihelion/aphelion, and so Mars's analemma is almost not a figure-8 (it is, but one lobe is very small.)
It's a misconception that the figure-8 shape is due to the eccentricity of the Earth's orbit. Most of the variation in the sun's horizontal apparent motion is also due to Earth's axial tilt. Orbital eccentricity only contributes the slight asymmetry seen in the final analemma. See my reply to the sibling comment for more detail.
The east-west component arises from this: When the Earth is at perihelion (January), the time from solar noon to solar noon is slightly longer, because the Earth is moving faster and farther in its orbit, so it has to rotate a bit more until the same meridian points back at the sun again. At aphelion (July), that's reversed, solar noon to solar noon is slightly shorter.
Put another way: A solar day is more than 360° of rotation relative to distant stars. It's very close to 361°, because the angle between the stars and the sun changes as the Earth advances in its orbit, by about a degree per day. At perihelion in January, it's slightly more yet again, like 361.0002°, and in July, it's 360.9998°; that difference takes a few seconds more or less to rotate. We don't vary our clocks based on that variable solar day duration; instead we fix our daily time intervals and let the sun's apparent position vary east-west slightly relative to that.
The figure-8 shape arises from the relative phase of the two cycles. The maximum velocity for the north-south component occurs at the equinoxes, while the maximum velocity for the east-west component occurs at perihelion/aphelion. On Earth, these occur at different times. Interestingly, for Mars the converse is true; its equinoxes are near its perihelion/aphelion, and so Mars's analemma is almost not a figure-8 (it is, but one lobe is very small.)