Water is a much better conductor of heat than air which is why you get cold so quickly whilst snorkelling. A wetsuit is used to create a thermal layer around your body to prevent cold water constantly flowing over your skin and also to trap heat that naturally escapes your body.
Wetsuits are typically made from foamed neoprene material that consists of tiny air bubbles trapped within a rubber material. The air bubbles are what provide the thermal insulation so, generally speaking, the thicker the neoprene the warmer the wetsuit. Alongside choosing the right thickness suit it is also important to pick a well-fitting suit that offers good seals around the arms/wrist, legs/wrists and neck, so that water doesn't flush in and wash out that nice warm water.
Neoprene isn't the only option though. There are a number of suits that are made from a combination of different materials with a breathable membrane sandwiched between them. These types of suits offer similar thermal properties to 2 to 2.5mm thick neoprene but aren't as buoyant and usually offer better wind chill protection.