All of the planets in the Solar System formed from the same cloud of debris. The inner planets have solid cores of iron, surrounded by rocky mantles, topped with a very thin silicate crust. The Gas Giants have solid cores of rock and ice, but these are much smaller in proportion to those of the inner planets. Jupiter and Saturn are made of hydrogen and helium, which becomes denser towards their centres. Uranus and Neptune both have mantles of icy water, methane and ammonia.

Astronomers think the giants first formed as rocky and icy planets similar to terrestrial planets. However, the size of the cores allowed these planets (particularly Jupiter and Saturn) to grab hydrogen and helium out of the gas cloud from which the sun was condensing, before the sun formed and blew most of the gas away. 

Since Uranus and Neptune are smaller and have bigger orbits, it was harder for them to collect hydrogen and helium as efficiently as Jupiter and Saturn. This likely explains why they are smaller than those two planets. On a percentage basis, their atmospheres are more “polluted” with heavier elements such as methane and ammonia because they are so much smaller.

Scientists have discovered thousands of exoplanets. Many of these happen to be “hot Jupiters,” or massive gas giants that are extremely close to their parent stars. (Rocky worlds are more abundant in the universe, according to estimates from Kepler.) Scientists speculate that large planets may have moved back and forth in their orbits before settling into their current configuration. But how much they moved is still a subject of debate.

There are dozens of moons around the giant planets. Many formed at the same time as their parent planets, which is implied if the planets rotate in the same direction as the planet close to the equator (such as the huge Jovian moons Io, Europa, Ganymede and Callisto.) But there are exceptions. 

One moon of Neptune, Triton, orbits the planet opposite to the direction Neptune spins — implying that Triton was captured, perhaps by Neptune’s once larger atmosphere, as it passed by. And there are many tiny moons in the solar system that rotate far from the equator of their planets, implying that they were also snagged by the immense gravitational pull.