Comets orbit in extremely elliptical paths, spending most of their time in the distant outer solar system (Oort cloud, Kuiper Belt) and briefly approaching the Sun. Gravitational interactions with giant planets scatter comets into observable orbits. Long-period comets come from the Oort cloud; short-period comets from the Kuiper Belt. Comets are icy remnants of planetary formation.
From orbital mechanics, you know that two bodies interacting gravitationally trace conic sections — ellipses, parabolas, or hyperbolas — depending on their total energy. Most planets orbit in nearly circular ellipses, but comets occupy the extreme end of the spectrum: highly eccentric ellipses (or sometimes parabolic/hyperbolic paths for one-time visitors). A comet with an eccentricity of 0.99 might have its closest approach to the Sun (perihelion) inside Earth's orbit while its farthest point (aphelion) lies beyond Neptune. This means a comet spends the vast majority of its orbital period in the cold, dark outer solar system, becoming visible only during its brief, dramatic swing near the Sun.
Comets are broadly classified by their orbital period. Short-period comets (periods under ~200 years) originate primarily from the Kuiper Belt, a disk-shaped region of icy bodies extending from Neptune's orbit outward to roughly 50 AU. These comets tend to orbit in or near the plane of the solar system, consistent with their disk-shaped source. Long-period comets (periods of thousands to millions of years) come from the Oort cloud, a spherical shell of icy bodies at distances of 2,000 to 100,000 AU. Because the Oort cloud is spherical, long-period comets arrive from all directions — their orbital inclinations are randomly distributed, unlike the more orderly short-period comets.
The mechanism that delivers comets to the inner solar system is gravitational perturbation. For Kuiper Belt objects, close encounters with Neptune can nudge an icy body into an orbit that crosses the paths of the giant planets. Each subsequent encounter with Jupiter or Saturn further alters the orbit, sometimes shortening the period dramatically — this is how Jupiter-family comets like 67P/Churyumov-Gerasimenko end up with periods of just a few years. For Oort cloud comets, the perturbations come from passing stars, the galactic tidal field, and encounters with giant molecular clouds, any of which can deflect a distant icy body into a plunging orbit toward the inner solar system.
Comets are primordial remnants — icy, dusty bodies left over from the era of planet formation some 4.6 billion years ago. Their composition (water ice, carbon dioxide, ammonia, silicate dust, and organic molecules) preserves a record of conditions in the early solar nebula. Each perihelion passage heats the surface, sublimating ices into a gaseous coma and producing the characteristic dust and ion tails. But this activity is also destructive: a comet loses mass with every pass near the Sun, and eventually it either breaks apart, exhausts its volatiles to become a dormant rocky body, or is ejected from the solar system entirely by a planetary encounter. The dynamical lifetimes of short-period comets are far shorter than the age of the solar system, confirming that the Kuiper Belt and Oort cloud must continuously resupply the inner solar system with fresh comets.