Comets, or their precursors, formed in the outer Solar System, possibly millions of years before planet formation. How and when comets formed is debated, with distinct implications for Solar System formation, dynamics, and geology. Three-dimensional computer simulations indicate the major structural features observed on cometary nuclei can be explained by pairwise low velocity accretion of weak cometesimals. The currently favored formation mechanism is that of the nebular hypothesis, which states that comets are probably a remnant of the original planetesimal "building blocks" from which the planets grew.