The S&P 500 (SNPINDEX:^GSPC) has been a big winner in 2016, bouncing back from a tough year in 2015 and picking up gains of more than 10% with just a few weeks left in the year. That might not sound like a major victory, but given a tough start in January and February, most investors have been generally pleased with the market's performance. Let's look more closely at how the S&P 500 did in 2016 and what events helped drive its ups and downs throughout the year.

^SPX Chart

^SPX data by YCharts

Commodities bounce back

From a big picture perspective, the best-performing sector within the S&P 500 in 2016 has been the energy sector. Yet it's important to put the year's gains in context. Even though energy's gains of about 25% for the year sound impressive, they essentially only got the group back up to where they had traded at the end of 2014, following 2015's disastrous plunge for the sector. That stands to reason, given that even with the gains that crude oil prices have enjoyed this year, the current range of around $50 to $55 per barrel is still far below the prices that prevailed throughout most of the early 2010s. ONEOK (NYSE:OKE) was the second-best performing stock in the S&P during 2016, with gains of nearly 150% showing how the midstream giant took advantage of better conditions in the energy markets throughout the year.

Materials stocks were also solid winners, with sector gains of 18%. Both precious metals and base metals posted good advances in many key markets, and copper played a vital role in helping to drive the performance of Freeport-McMoRan (NYSE:FCX), the index's third-best performing stock with a rise of 133%. Freeport has energy exposure as well as producing copper and gold, and that combination helped the company this year even as it had punished the stock in 2015.

Stock Chart Gettyimages
Image source: Getty Images.

Other winners and losers

Beyond commodities, the financial sector was the other big winner on the year, climbing 22%. Most of those gains have come in just the past month and a half, with investors celebrating the victory of President-elect Donald Trump and foreseeing favorable outcomes for the broader economy and the financial companies that help finance its growth. In particular, expectations for rising interest rates have already made themselves apparent in the bond market, and a steeper yield curve is favorable not just for retail banks but also for more investment-centered financial institutions.

Meanwhile, the worst-performing sector of the year was healthcare, which suffered a 5% decline. Much of the year, drug companies got pressure from politicians looking to cut their profit margin on their treatments. Even the Trump victory didn't eliminate that pressure, with the President-elect having recently commented that some drug prices remain too high. The expected revamping of the Affordable Care Act is also creating uncertainty within the sector, with potential winners and losers among healthcare companies with different niches. Several companies in the healthcare space were among the worst performers in the S&P 500, largely because of failed candidate treatments that didn't live up to expectations.

Welcome to the S&P 500!

Each year, the S&P 500 changes its constituent list, and 2016 brought some popular names into the list. Under Armour (NYSE:UAA) entered the ranks of the index in March, having earned its way into the top echelon of U.S. companies by successfully muscling its way into the athletic apparel and footwear space. Stellar growth got Under Armour to where it is now, and even though its recent share-price performance has reflected some setbacks, few question the company's long-term prospects.

A better performer among the newest members of the S&P 500 was Ulta Salon (NASDAQ:ULTA), which has used its unique business model to power gains of more than 35% so far this year. Ulta combines a full line of premium beauty products with in-store salons to help customers get the full-service experience they want. For years, Ulta has grown its network of salon locations across the country, and even in an environment in which luxury retail suffered, Ulta has found the right balance to appeal to its customer base and keep them coming back for more.

Finally, Alaska Air Group (NYSE:ALK) made the S&P 500 in May. Airlines had an up-and-down year in 2016, but Alaska had taken full advantage of fuel price declines in 2015 to produce strong returns for its shareholders. Some haven't been certain about the airline's $2.6 billion bid to buy Virgin America, but a more fuel-efficient fleet and its efforts to become the most attractive airline on the West Coast of the U.S. appear likely to pay off in the long run. Now that the merger has finally gotten approval, investors will soon be able to see what happens with the joint company moving forward.

The S&P 500's returns in 2016 haven't been among the strongest the index has ever seen. But as the bull market approaches the end of its eighth year, double-digit percentage gains for the S&P 500 aren't something to scoff at -- and long-term investors have reaped the rewards of their patience in sticking with the market even through rough patches during the beginning of the year.

Dan Caplinger has no position in any stocks mentioned. The Motley Fool owns shares of and recommends ONEOK, Ulta Salon, Cosmetics and Fragrance, and Under Armour (A Shares). The Motley Fool owns shares of Freeport-McMoRan Copper and Gold. Try any of our Foolish newsletter services free for 30 days. We Fools may not all hold the same opinions, but we all believe that considering a diverse range of insights makes us better investors. The Motley Fool has a disclosure policy.