RV64I is a superset of RV32I with the exception of SLLI, SRLI and SRAI. For those instructions the shamt field increased by one bit. In RV32I all instructions operate on 32 bit data. The same instruction will operate on 64 bit data on RV64I. For operations on the lower 32 bit additional instructions are included in RV64I.
A program compiled for RV32I can work on a RV64I machine. It will run without generating an illegal instruction exception but the result will most probably be wrong. So programs compiled for RV32I will only work properly on RV32I machines and programs compiled for RV64I will only work on RV64I machines.
For programs that contain mixed binaries, like bootloader, kernels or firmware, the misa register encodes the register width in the top bits so it is possible to jump to the correct binary with jumps and left shifts. See Priviledged Spec p.15
It is possible for an implementation to support both RV32I and RV64I but this requires support from the system software.