Containers, by design, are a very flexible method of transporting goods. You'll see almost any combination of containers in cars. The only thing you can't do, is put 20' containers on top of 40' or larger.
20' containers have mounting holes at the corners, so there is 20' separation.
40', 45', 48' and 53' containers have mounting holes 40' apart with no mounting hole at the 20' mark. This means that a 40' or larger container can sit on top of two 20' containers, there is no way to mount two 20' containers on top of a larger one.
Railroad try to maximize revenue per car, so in an ideal world well cars large enough to hold 53' containers would, ideally, be only loaded with 53' containers. In the real world, this is not the case. You can find any size container that will fit a car in it. In some cases, a car designed for 40' containers will have a 40' container in the bottom position with a 45', 48' or even 53' container on top! And then the next car, designed for 53' containers will have two 40' containers stacked in it!
Around my home town, there is a tunnel that is too short to double stack domestic containers, so most double stack cars around here aren't stacked at all. The shorter overseas containers can be double stacked. So that creates a nice variation where 20' and 40' containers can be double stacked, but the 48' and 53' can't be.
As a general rule of thumb, don't put 20' containers in the top position, they should always be on the bottom.
In the modeling world, most containers can be stacked with each other, but stack best with other containers by the same manufacturer. Concor containers have the pins and holes reversed compared to the majority of manufacturers, so watch out for those ones.