Food can become contaminated with bacteria during various stages of production, processing, handling, and storage. This can happen through cross-contamination from raw foods to cooked foods, inadequate cooking temperatures, poor hygiene practices, and unsanitary conditions. It is crucial to ensure proper food safety measures are followed to prevent bacterial contamination.