Thin metal strips called frets are inlaid across the fingerboard. When you push down on a string, the fret acts as a contact point, setting the length of the string's vibrating portion and, therefore, the exact note that you hear. There's no "official" number of frets, but most electric guitars have 20 to 24, and acoustic guitars have 18 to 24.
The frets on the bass separate the notes from one another. (Memorize the frets with the dot-markers on them. They are all odd number frets except the twelfth fret, and also the twenty-fourth fret on basses with twenty-four frets.)