Dental fillings are used to fill in the void caused when tooth decay or caries is removed from a tooth. Tooth decay fillings are done when a bacterial infection much like a rotten place in a fruit destroys part of the tooth. It softens the tooth and will eventually make a hole in the tooth which coined the term "cavity." Dental fillings are made of two different materials. The oldest material is called amalgam, also know as silver fillings because of the silver color. Amalgam is still used in the United States although it has been banned in many European countries because of the Mercury that it contains and the possible health concerns associated with Mercury. The newer material is called composite, these are tooth colored fillings. It is made of a composite of resin and glass fillers and is tooth colored.
When a filling is recommended, it is usually because there is an infection in the tooth, whether it be an infection in a tooth that has never had a filling before, or a secondary infection around an older filling. If a filling is being recommended then the damage done to the tooth is probably early to moderate damage. If the tooth has too much damage, other treatments may be recommended such as a crown and/or a root canal.
When a tooth has a cavity, the rotten part of the tooth is usually much larger than can be detected by looking from the outside. The tooth is covered with enamel, which is the hardest material in the body - it is much harder than bone. It is made to withstand crushing forces while eating and is used in forensics because it can withstand many environments without breaking down. The substructure of the teeth lying under the enamel is called dentin. It is the yellow structure in the pictures below. It is not as hard and is less resistant to the bacterial infection (the brown part of in the picture) as you can see the infection spreads and is much larger once it gets to the dentin. This is why it is important to stop tooth decay as soon as it is notices, because it is usually bigger than you realize at the time it is first noticed
If the tooth already has a filling, although they are called "permanent fillings," they do not last forever. They are called permanent because there is not a plan to replace them in the near future, however the tooth structure around the filling is still subject to infection, especially at the margin between the filling and the tooth. If tooth decay is noticed around an old filling, the filling and any underlying tooth decay should be removed and a new filling placed. There are a few signs that indicate that a filling may have tooth decay around it or under it. With a silver amalgam filling you can see the tooth start turning dark around the filling, you may notice a tine gap forming around the filling which lets bacteria in, or there may be a crack in the tooth around the filling or in the filling itself which all allow tiny bacterial access to a deeper part of the tooth. These area all reasons to replace an old filling. With a tooth colored filling, you can see a brown line around the edge. Below is a tooth with a silver filling and it shows what is under these fillings when they begin to get a secondary infection and how much structure needs to be removed indicating that it is urgent to replace these fillings as soon as the signs are notices to reduce the amount of tooth structure that is lost.