There are different type of bacterial infection, and cause depends on where..
For example, infection in the brain (meningitis, encephalitis), could be caused by bacteria that you come in contact with, from an infected person..
Infection in the lungs (pneumonia) could be cause by inhaling bacteria from an infected person
In the urinary system, could be caused by bacteria ascending from poor wiping after a long call
Treatment and prevention depends on the cause and location of the infection…so may be ask for a specific one and I can try explain further?