>>8078386As for what, exactly, they can change into the TV series glosses over it, but it also has like eight different ways for them to be born, formed, or built so it's a crapshoot.
The IDW comics go into it a bit deeper, transformers are generally either naturally born (their spark originates from the planet itself and they grow into a body with a natural altmode that best suits them) or "Cold Constructed", basically a shell body with a specific altmode for a specific purpose is built and then brought to life with a mass-produced manufactured spark.
A Transformers altmode or altmodes, then, depend on the nature of their creation, their personality and aptitudes, and personal ability. Some transformers (like Sixshot) mastered multiple alternate forms through training. Others, like Starscream, just have new bodies built whenever they feel like it like changing a suit.
So ultimately the answer is "whatever the writer of what you're watching/reading felt like"