Azoospermia is a situation in which the germ line of the testicle has been damaged. Basically, the testicle is a structure formed by stroma with Sertoli cells, which support the germ cells and deal with the male hormonal system. The germ line are cells that give rise to sperm, and are in principle active from puberty and throughout the male's life.
These cells can be affected by multiple causes. The destruction of these cells results in the absence of sperm in the ejaculate (azoospermia).
Most of the time the problem is constitutional, either due to genetic failure or congenital affection the male is born without germ line, so this azoospermia cannot be prevented.
Other causes of azoospermia, which we would call secondary, occur as a consequence of testicular damage (trauma, radiation, surgery, toxins, tumors...). Under this point of view, care for the testicular germline through healthy living habits (balanced diet, non-extreme sport, avoidance of toxins) can prevent azoospermia in some cases. Likewise, the male testicle should be protected in procedures involving the absorption of ionizing radiation in the area.
Finally, it is necessary to comment on obstructive azoospermia. Although this seminal alteration may also be genetic (cystic fibrosis), in most cases it is acquired. Therefore, avoiding infections and trauma and healthy lifestyle habits are ways to prevent azoospermia.