The tooth has 3 layers:
Enamel (Outer white)
Dentin (Middle yellow)
Pulp (Inner red)
The pulp has nerves & blood vessels within then which provides sensation (Hot, Cold, Pain) & nutrition to the tooth.
If there is any infection/ inflammation / trauma related to the pulp then the tooth starts paining (most of the times).
In order to save the tooth a root canal treatment needs to be performed.
A surface anesthetic spray or jelly is applied on the area to be injected so that the anesthetic injection becomes painless. After waiting for a couple of minutes the anesthetic is administered to numb the area.
Now that the tooth is numb, a high speed drill is used to remove the decayed portion of the tooth without any pain.
A small opening is created in the tooth to access the pulp of the tooth.
Removing the pulp eliminates the infection & hence the pain too.
Mechanical debridement of the root canal system is done with small instruments and washed away with disinfection solutions to make the tooth germ free.
The space inside the root canal is filled with a material called gutta-percha and sealed so that the system should not get infected again.
Now that the tooth is infection free and sealed, the cavity is filled with a restorative material like cement, composite or a silver filling.