We review recent advances in our understanding of the origin of the initial mass function (IMF). We emphasize the use of numerical simulations to investigate how each physical process involved in star formation affects the resulting IMF. We stress that it is insufficient to just reproduce the IMF, but that any successful model needs to account for the many observed properties of star forming regions including clustering, mass segregation and binarity. Fragmentation involving the interplay of gravity, turbulence, and thermal effects is probably responsible for setting the characteristic stellar mass. Low-mass stars and brown dwarfs can form through the fragmentation of dense filaments and disks, possibly followed by early ejection from these dense environments which truncates their growth in mass. Higher-mass stars and the Salpeter-like slope of the IMF are most likely formed through continued accretion in a clustered environment. The effects of feedback and magnetic fields on the origin of the IMF are still largely unclear. Lastly, we discuss a number of outstanding problems that need to be addressed in order to develop a complete theory for the origin of the IMF.