The majority of drugs that are used by competitors can be detected in a sample of urine. For some substances however, a blood sample may be required.
Analytical chemistry techniques (such as mass spectrometry and gas chromatography) are used in conjunction with biological techniques (immuno-assays) to identify the type and amount of most banned substances in the body.
The problem is that as fast as scientists devise new tests, other scientists are devising new products that enhance performance.
Many tests look for indications that a drug has been used rather than looking for the actual drug itself - for instance raised levels of hormones in the body.
The problem arises when deciding exactly what changes in the body indicate the use of a banned substance and how long the effects of a drug might last. Furthermore virtually all banned substances occur naturally in the body so it is a matter of what level of substance is detected.
Further details of procedures for drug testing can be found in the following document: