Snakes have nostrils, just like humans. They have a fully developed olfactory system and can smell with their nostrils, just as we can, but their tongues are the most important props for smelling.
Most of the snake's tongue is hidden inside a sheath in the lower jaw when it is retracted. When the snake does flick its tongue, it passes through a small notch in the lip which allows the tongue to pass without the mouth having to be actually opened.
When a snake's tongue is flicked into the air, receptors on the tongue pick up tiny chemical particles, which are perceived as scent. When the tongue is retracted into its sheath, the tips of the tongue fit neatly into a special organ called the vomeronasal system (or Jacobson's organ) sending the chemical information to the brain. This way the snakes "smell" things like dirt, plants and other animals, helping them avoid predators or catching prey.