When the bacteria is starving or senses a change in the environment, like extreme temperatures and drought, they will produce a spore. This spore is a protective, thick cell wall and can help the bacteria survive for several years by living in a dormant state. The spore is made up of few things but includes peptidoglycan, cytoplasm, water, and bacterial DNA. Once environmental conditions improve, the spore will break.
Some bacteria species forms spores to protect themselves from unsuitable environment conditions or from exposure to toxic chemicals. Spores are thermostable and impermeable to different xenobiotics, such as antimicrobial agents, toxins etc,
Christian: "how" pertains to the material and efficient causes; "why" pertains to the formal and the final causes. Both "how?" and "why?" are answerable, and in the realm of natural phenomena, always answerable..