Stars constitute undoublty one of the elementary blocks of the Universe and play as such a central role in determining for
instance its chemical evolution. They can be seen as modern physics laboratory from which fundamental processes as diverse as atomic physics or turbulence can be studied and understood. Being able to model accurately their structure, dynamic and evolution is thus of fundamental importance and is the subject of intense research. In this short lecture we will first discuss the basic equations and processes, such as convection, turbulence, rotation, instabilities and dynamo action that are at the origin of the magnetic field observed in stars. We will then present some of the numerical simulations in three dimensions performed in recent years to model such complex objects and their nonlinear behavior, focussing mainly on results obtained with the anelastic spherical harmonic (ASH) code. Using the Sun as a reference star, we wish to gain insight the various magnetohydrodynamical processes that shape its large scale dynamics and magnetism, such as the Reynolds and Maxwell stresses, and the ω and α-effects. We will then extend our study to other stars, such as young Suns, massive stars or evolved RGB stars in order to identify which processes are at the origin of their significantly different dynamics.