There are nine official classes that can be played in Team Fortress 2; they are as follows:
All nine classes are grouped into three specific combat types, offensive, defensive, and support, but all can be played outside their assigned role depending on the player's choice of strategy.
Offensive classes, Scout, Soldier, and Pyro are the main attack force of the team. Whether it's assaulting Control Points or grabbing the Intelligence, these classes focus on mobility. Scouts have the ability to capture points twice as fast as any other class and can get there with their top-tier speed and double jumps. Soldiers pack a punch with their devastating Rocket Launchers, and can attack from unexpected directions by rocket jumping. Pyros can wreak fiery havoc in enemy ranks with a well-timed ambush or extinguish their own burning friends, and offer the highest speed/health ratio of all classes (barring buffs or nonstandard equipment).
The defense classes, Demoman, Heavy, and Engineer serve to inhibit enemy access and to hold enemies back from vital points on the map. Overall, the defensive group has the most firepower of all the groups. Demoman can safeguard areas with stickybombs that they can detonate when pressing Right Click. Heavies are great for mowing down incoming troops and pushing back forces. Heavies can also keep enemies in an area while whittling their health for teammates to finish off. Engineers can build Sentry Guns for effective area defense, as well as build Teleporters and Dispensers for logistical support of the team.
The support classes, Medic, Sniper, and Spy serve to help something or replenish something. Medic is a self explanatory class, the Medic's job is to go around and heal any class that has a low health count in sight. The Sniper inflicts critical hits when they shoot someone in the head. He can kill any class with a fully charged headshot. The Spy can provide support by sapping the Engineer's buildings, weakening the defense of the enemy team so other Support, Defense, and Offense classes can get through unharmed. Spy also can kill any class with a stab to the back, go invisible, and disguise as the friendly team or the enemy team to confuse the enemy. Spy is usually the hardest one to play in this category.