This is a great anatomy figure from my book, I’m a Boy, My Changing Body. It shows that the testicles are located in a pouch of skin located outside the core of the body. The pouch of skin is called the scrotum.
Illustration from I’m a Boy, My Changing Body
Sperm are produced in the testicles, but developing sperm are very sensitive to temperature. If the surrounding temperature is a few degrees too high or too low, sperm production is limited.
This is the reason that the testicles are located in the scrotum and not inside the pelvic cavity where other male reproductive structures are found. Because the scrotum is simply a sack of skin, the temperature inside is cooler. If the scrotum becomes too cool, tiny muscles that surround the testicles pull the testicles closer to the core of the body to keep them warm.
The boy is clever. It is very important to protect the testicles so that the sperm being made inside are also protected.