Choosing the best underwear for certain situations is important something; however, at the gym/when working out may be one of the most crucial times where wearing the best underwear is key. People wear a variety of different styles at the gym for a number of reasons; for comfort, support, helping muscles prevent early fatigue, moisture wicking so-as not to have sweat all over the ENTIRE body, and let's face it....the gym is a huge check-out/cruising spot. For many it's just window shopping at it's finest, but other try out the merchandise (sometimes in the "store" itself. So underwear is important for gym goers. All the "gym" underwear usually can come in a variety of materials from plain cotton, to moisture wick, to micro-fiber, to mesh breathable fabrics.
First, there's the boxer-brief. They fit more snug on the upper thighs and offer a little compression support to prevent from unnecessary "flopping" or moving of anything that you wouldn't want moving while working out or running on the treadmill.
Then there's the average brief or hip brief. This adds more support for your junk and has less fabric; therefore, avoiding unnecessary rubbing. Briefs also often make the appearance of certain things "pop" more if you're looking to have certain attributes noticed (and I don't just mean your biceps).
There's the compression underwear made by many athletic clothing companies. This underwear is almost always made from material that wicks moisture. The added benefit of compression underwear is that the tight pressure that they apply to the thighs (and whole leg if wearing long underwear) has been scientifically proven to increase endurance for runners and bikers by delaying fatigue of muscles.
The athletic brief and jock. These two types offer the least amount of clothing on the body. The athletic brief having a regular brief bum and then a pouch-like front with nothing on the sides. And the jock is pouch-like in the front with open bum and only two straps wrapping around the bum/upper thighs for support. Often worn for comfort and for less rubbing of fabric. I also know that many people perfect jocks (and other underwear with less fabric, especially on the ass) because it prevents sweating. These two can also be a lot more revealing in the locker rooms (again for the "shopping").
At the end of the day, what underwear you wear at the gym is personal preference (just like who at the gym you would like to see in their underwear). Trial and error or word of mouth are the two best ways to discover what works best for you. Currently I prefer Calvin Klein athletic briefs or athletic hip briefs that are a mesh material. They're amazingly comfortable and don't move much when I workout or do my cardio; while the mesh prevents sweating and allows breathability as well as looking good (if I can say that about myself lol).