The "bugs" you find on a dead body can tell a forensic entomologist how long the body has been dead. The entomologist will not be able to give you an exact time of death, but rather an estimate. This estimate will always be a range of time. This range will vary from a few hours for bodies that have been dead for a day or two, to perhaps several months for bodies that have been dead for several years. This flyer is a brief description of how entomologists obtain their estimates from insect evidence.
The idea behind using insects to estimate a minimum PMI, or post-mortem interval, is based on how the insects develop or grow up. Some insects--those with a so-called "complete" metamorphosis--have immature stages whose movement is extremely limited, but have adults that are among the most mobile animals on earth. Some of these insects are specialized to develop on dead animals or carrion, including corpses. The adults fly far and wide searching for a suitable corpse. When they find one, they lay their eggs. These eggs develop into larvae--white flabby eating machines that grow by eating the corpse. The larvae cannot move far, and eventually change into winged adults via an intermediate stage called the pupa. Therefore, if one collects an egg, larva, or pupa of one of these carrion insects on a corpse, this egg, larva, or pupa had to develop at that corpse and did not come in already formed from somewhere else. If an entomologist knows how long after death the eggs are laid, and how fast the larvae grow, he then has the length of time the corpse must have been exposed to insects. This length of time is the minimum PMI.
As I said, an entomologist needs to know two items to arrive at a PMI. He finds both of these things out by knowing what insect he is dealing with. Knowing the species of insect allows him to go to the scientific literature. If the information is there, he can get it.
He also needs to have some sort of estimate of the temperature the insects developed at. Larval developmental times vary with temperature. Larvae take more time to grow at low temperatures than if temperatures are higher.
If all of this information exists the entomologist can put it together to obtain a fairly precise estimate of the minimum time the body must have been accessible to insects. For example, let us say that a coroner collects the newly-formed pupae of a particular fly at a corpse. The entomologist knows that this particular fly usually arrives at a corpse within an hour of death, and that the eggs take an average of 500 hours (490 to 510) to become pupae at the temperature of the corpse. He can then say the PMI was probably 501 hours, and certainly no lower than 491 hours or no greater than 511 hours. This is a greatly simplified case, because we have assumed the temperature of the corpse was constant, and that the information on the development of the fly was obtained at that temperature. But there are also methods for transforming data taken at one temperature to their value at another temperature, and methods for analyzing data in relation to variable temperatures. These methods are much too complex to go into here.