Comets that appear in the inner solar system have generally been pulled by the sun's gravity from one of two large clouds in the outer solar system. The cometary nuclei in these formations, the Kuiper belt and the Oort cloud, formed around the same time in the early solar system. Since that time, around 4.6 billion years ago, the Kuiper belt has changed very little.
Long-period comets orbit the sun along large, highly elliptical paths that terminate very far beyond the orbit of Neptune. This cloud, which is named for Dutch astronomer Jan van Oort, formed as a result of the chaotic gravitational interactions of the early solar system. The Oort cloud comets formed interior to the orbit of Jupiter but were attracted by the gravity of the giant planet. After being released from the pull of Jupiter, these comets were hurled far out into the outer solar system. Many of these comets were probably lost to interstellar space, while others collided with planets or the sun. Some, perhaps trillions, fell into orbits that take them from close to the sun out to a distance between 50,000 and 100,000 AU (an astronomical measurement equivalent to the distance from the earth to the sun).
Solitary comets occasionally fall into one-way descents into the inner solar system. These comets may have been disturbed by the passage of a nearby star, or they might be fragments of a deep-space collision that set them on a terminal course toward the sun or Jupiter.