[TLDR: The gradient coils.]
That is a great question. There are three parts to an MRI machine: main magnetic field (1.5 Tesla, 3 Tesla etc), gradient coil system and radio-frequency coil.
The main magnetic field is static, meaning is doesn't change. Once the technician has "ramped up" the scanner, it will not change. It doesn't get shut down at all. So, this part of the system is quiet.
The radio frequency (RF) coil is typically what is placed on or around the person's head, shoulder, knee etc. The RF coil both sends radio frequencies into the body and receives radio frequencies from the body. This is the way data is "read" from an MRI scanner. The RF coil is quiet too.
The gradient coils are a separate set of coils inside the scanner shrouding (so you don't see them) that are (typically) cylindrical in shape, so the MRI bed is basically sliding you inside them. The magnetic field gradient coils have electrical impulses put through them at a very, very fast rate (millisecond range). So, the electricity going through them at such a high rate produces mechanical torque (meaning the coils actual twist slightly) and that is what you are hearing. NOW, with all that being said, they are manufactured with very strict safety constraints etc so the torquing is not something to be worried about. :)
Most scans are acquired as "lines" of data and each line of data is typically one quick set of noises you hear. [The line of data is acquired in "Fourier space" which is the Fourier transform of image space.] Any movement even during the quiet periods can or will typically produce artifacts in the images. So it is best to stay as still as comfortably possible during the scan.
Further good questions... So, a typical MRI scan (20-40 minute session) consists of, typically 3-5 scans. Each scan has different parameters in order to create images with different contrast. Each manufacturer might have a slightly different procedure but here is typically how things work...
Given one of the scans there are typically two parts to it.
The first part, which lasts 10s of seconds, or so, is a tuning part. And, this consists of a few parts. So, the first tuning part of the sequence determines how much radio frequency (RF) power needs to be used to get some pre-determined affect (usually a 90 degree pulse). This will sound like just a few clicks spaced apart by ~1s. Once the RF power is determined, then it uses that information and runs a very short part of the MRI scan to make sure the data coming back is decent (in very general terms).
Once all this tuning stuff is done, then the actual MRI scan runs. This is the part that will run for a few minutes to many minutes (typically). The main part of the MRI scan typically has a very short RF pulse played out, then the gradient coil plays (to do spatial encoding) and then there is a delay. This whole thing is repeated many times to acquire all the data. The delay can be very short (milliseconds) or very long (~seconds). The time from when the RF pulse is played out to the end of the delay is the TR time (repetition time). There is a decent description of the relationship of all these things here.
So, for the actual scan:
RF pulse -- Gradients ---- delay
^------------- TR -------------^
And this block is repeated.
To go even one more step further, one can add some RF and gradient stuff before each RF pulse (above) as a way of creating even different contrast than normal in the images. That is a whole different topic.
For example, a typical brain scan for multiple sclerosis might consist of:
- Dual echo spin echo, this one will have a relatively long delay for each TR interval (~second or so).
- T1-weighted scan, this one will have a relatively short delay for each TR interval (~50-100 milliseconds or so).
Oh, and one other thing. For the most part, MRI scans are not "adapative" in the sense that usually they don't acquire a bit of data and then check to see if it is good, and then decide to keep it or not. Most scans these days are done and then the MRI technician will check to see if the whole thing needs to be repeated. Some scans can kind of do adaptive scanning but I think that technology on a hospital scanner is still being develped and something to come in the future.
There are so many interesting things here, and so many more details. I have to admit, I really enjoy MRI.