In the Ptolemaic system of astronomy, the epicycle (literally: on the cycle in Greek) was a geometric model to explain the variations in speed and direction of the apparent motion of the Moon, Sun, and planets. It was designed by Apollonius of Perga at the end of the 3rd century BC. In particular it explained retrograde motion.
In the Ptolemaic system, the planets are assumed to move in a small circle, called an epicycle, which in turn moves along a larger circle called a deferent. Both circles rotate counterclockwise and are roughly parallel to the Earth's plane of orbit (ecliptic). The orbits of planets in this system are epitrochoids, and the point around which an epicyclic path revolves is the equant.
The deferent would be considered to be centered on the Earth (as the planet was believed to be in orbit around Earth... see: geocentric universe).
As viewed from Earth, the planets were seen as mostly moving eastward along the deferent. Half of the time, the added motion along the epicycle was eastward, in parallel with the eastward movement of the epicycle on the deference. However, at times the planet would move along the epicycle in an opposite direction to the motion of the epicycle along the deferent. This would cause the planet to slow down and reverse course, ie. retrogradation.
Over time more levels of epicycles (circles within circles) were added to the models, to match more accurately the observed planetary motions. Yet more levels of circles were not found sufficient in some cases, and "offsets" or "bars" were added to the models to compensate. This gradual process of going from a simple model to a complex model is sometimes used as an allegory for some modern technical "boondoggles". To be fair, however, the actual proliferation of epicycles that occurred has sometimes been exaggerated in modern times. During the time when the Ptolemaic system was in use people had neither the observational precision nor the mathematical methods necessary to recognize and "correct" the deviations of the planets' motions from the predictions of relatively simple epicyclic models.
The switch to the Sun-centered model removed epicycles for a while, but the original versions insisted on circular orbits for the planets. Better observational data from improved telescopes once again showed data counter to the model, and epicycles were brought back to plug the holes. It wasn't until Kepler developed the elliptical orbital model that epicycles were finally eliminated.