# Magnet alignment within solenoid

Imagine I have a solenoid connected to a power supply. Solenoid produces an electromagnetic field. Now I take a permanent magnet and place it inside the solenoid. How will the magnet align itself (assuming there is no gravity) inside the solenoid and will it rotate itself around the central axis "aligning" itself?

From these two cases cases, which one is correct behaviour and where would the "north" pole point (up, down, left or right):

One:

Two:

P.S. What if the magnet is shaped differently, for example like a horseshoe, will it change its behaviour?

-

As Wikipedia will inform you, a dipole magnet in a magnetic field $\mathbf B$ will be subject to a torque $$\mathbf \tau=\mathbf m\times\mathbf B,$$ where the magnetic dipole $\mathbf m$ points from the magnet's south pole to its north pole. Thus the equilibrium positions are parallel and antiparallel to the field, so the situation will look like your first picture.
Note also that there are two orientations for the magnet, of which one will be stable and one will be unstable. To discriminate between the two, you need to choose the configuration that minimizes the energy, $$U=-\mathbf m\cdot\mathbf B,$$ so $\mathbf m$ will be parallel to the magnetic field. (To find out in which direction that goes, see this answer.