Abstract We present a physics-based finite element simulation of self folding of a hydrogel bilayer with programmed holes. Introducing holes in a bilayer modifies the topology and boundary of the bilayer. Early state swelling of a hydrogel bilayer forms rolled tubes along the periphery of the bilayer and adds the local rigidity along the boundary. Our numerical simulation shows that formation of rolled edges switches the deformation mode of hydrogel bilayer from slow and gradual bending to fast and sudden buckling or folding. On demand folding is thus possible by tuning the location, size and shape of holes. The uncovered folding mechanism is leveraged to design a number of soft self-folding machines. The results throw light on design and simulation of soft self-folding machines.