Long story short and many arguments oncoming, the vast majority recommend the following:
1) Glass tanks with trim, no foam (can actually cause issues instead of fixing them if done improperly).
2) Flat bottom tanks (all acrylic and/or glass tanks without a trim on any corners), foam. The type of foam, thickness, etc depends on the tank, size, etc.
3) If you ignore #1 and #2, whatever the manufacture recommends (which is typically matches #1 and #2).
Many try to put foam under their glass trimmed tanks to fix issues with the stand or "try to make it level", but that's not the solution to the problem.