A cavity is a hole in a tooth that is caused by bacteria. This hole can vary in size. When the hole is very large and touches the nerve inside the tooth, the cavity causes tooth pain. The best time to fill the hole/cavity in the tooth is when it is small as to avoid getting near the nerve. If a filling is placed too close to the nerve, because of the size of the cavity, the tooth can continue to hurt and may need a root canal.