Earthworms are hermaphroditic annelids that help keep gardens lush and soil productive by aerating the soil. While earthworms are common in many environments, they are seldom found in highly acidic or highly alkaline soils.
Acidity or alkalinity are measured on a scale of 1.0 to 14.0 called the pH scale. A pH of 7.0 is neutral---neither alkaline nor acidic. Different species of earthworms have different preferences, but most species prefer soil with a pH between 5.0 and 7.4. This range is similar to that preferred by most plants.
Earthworms are scarce in highly acidic soils---those with a pH below 4.5. They are absent from soils with a pH below 3.5. If your soil pH is below 4.5, increasing the soil pH could help increase the number of earthworms. Earthworms don't like highly alkaline soils either, however, so don't increase the pH above their preferred range.
Low soil pH could affect earthworms in one of two ways. Low soil pH may have deleterious effects on an earthworm's physiology, or it could be that low pH denies the earthworm some of the nutrients it needs. It isn't currently known which of these two factors is more important in determining earthworm pH preference.