How do I calibrate the extruder of my printer?
Basic process

To calibrate the extruder you would need to verify that the
requested amount of filament is actually what is being moved by the extruder.


Structural or temporary problem
A first thing to check when under or over-extrusion is encountered for a fresh spool of filament on a normally good working printer is to check the diameter of the filament with a caliper (see image below) and change this value accordingly in the slicer software of your choice and make a test print. If the problem persists or is present from the start of your purchase or build, please proceed. Note that there are two ways to change the extrusion, a simple solution is changing the extrusion multiplier in the slicer software, the better one is to fix the extrusion rate in the firmware.

Please note that you should measure the filament diameter at several positions

3D printer
There is a difference between DIY and commercial printers. Usually a commercial printer of decent quality rarely needs to be adjusted (as this is the job of the manufacturer). But cheap, commercial clones of well known printers, may need adjusting. Depending on the ability to change the settings of the software/firmware (closed or open source, or type of firmware), the user may (or may not) be allowed to change the values through configuration files or G-code commands.
For DIY printers, the builder is responsible for the printer as a whole and thus entrusted with the software/firmware setup of the printer controller board. The chosen printer firmware and its configuration should be done based on the printer layout and used hardware (also electronics like stepper drivers, remember the micro steps setting) which e.g. determines the amount of steps that are required to move an axis a certain amount of millimeters (steps/mm). This also applies to the extruder stepper. To start with a value of steps per mm, you could search the internet for your extruder type and recalculate the steps/mm roughly keeping your specifically used micro step value of the used stepper driver (which is set by dip switches or jumper caps an the printer board) in mind. With this basic setting you will be able to do a test.

Calibrate extruder (hot or cold)
When you have a printer, or build a printer and uploaded a rough setting for the extruder steps per mm, please test the amount of extruded filament. It is customary to mark the filament with respect to a certain reference point, then extrude e.g. 100 mm, and then check the distance the mark on the filament has traveled. The distance should be 100 mm, if not, you should change the value of the steps/mm in the firmware. To extrude 100 mm you will need to send instructions to your printer over USB connection using a terminal or graphical user interface typically found in freeware applications as Pronterface, Repetier-Host, OctoPrint, etc. or by creating .gcode text files with specific instructions and load the models through the menu of the printer from e.g. SD-card.
The G-code G1 E100 F100 commands the extruder stepper to move 100 mm in 100 mm per minute (please lookup if these G-codes are supported by your firmware!). Be sure that you have preheated the nozzle prior to extruding, many firmware's have built in protection to disallow extrusion below a certain temperature of the nozzle. For SD-card printing, e.g. for PLA you should preheat the nozzle to e.g. 195 °C with M109 S195 and as such must be placed before the actual extrusion command.
If the measured distance is different than the instructed length, a simple calculation will determine your follow up actions. E.g. if the instructed length of 100 mm is in reality 95 mm, the extruder should extrude (100 - 95) / 95) * 100 = 5.2 % more, or similarly said, the extrusion needs to be multiplied by 1.052. This could be applied in the slicer, but when this is a structural problem you should fix this in the firmware itself. This can be done by adjusting the printer configuration file and uploading new firmware (and settings) or for some printer firmware solutions use the same method as previously used to instruct to extrude filament. The G-code for setting the extruder steps in Marlin firmware is M92 if done with codes. If the original value (can be obtained with the command M503) is e.g. 400 steps per mm, the value should be changed to 100/95 * 400 = 421 steps/mm. The command M92 E421 will set the new value which can be saved to memory (so that it is available after a printer power off/on cycle) using M500.
When the configuration file approach is used, the following line in the configuration:
/**
 * Default Axis Steps Per Unit (steps/mm)
 * Override with M92
 *                                      X, Y, Z, E0 [, E1[, E2[, E3[, E4]]]]
 */
#define DEFAULT_AXIS_STEPS_PER_UNIT   { 100, 100, 200, 400 }
needs to be adjusted to:
#define DEFAULT_AXIS_STEPS_PER_UNIT   { 100, 100, 200, 421 }
You can do this a few times to fine tune the extrusion process.
For people that have a Bowden setup and firmware that supports altering the minimum extrusion temperature, you could disconnect the Bowden tube to ignore the hotend heat up by temporarily disabling the cold extrusion limit (M302 will display the current value) with M302 S0. After calibration please remember to set it back, e.g. M302 S170. Do note that temperature and extrusion speed do influence the extrusion process, so you might want to fine tune the extrusion process at temperature.
Now you printer extruder is tuned and should extrude the exact amount as instructed.

Fine tuning
Although the extruder may now be correctly tuned to extrude exactly the amount as instructed, the slicer may have a different view. Be sure to set the slicer extrusion multiplier to 1.0 when fine tuning the extruder/slicer combination. The ultimate fine tuning starts with printing an object with zero bottom and top layers and a single perimeter with a fine layer height (0.1 or 0.15 mm).

Measure the thickness of the wall and adjust your slicer extrusion multiplier accordingly. The rationale behind this is that the extrusion of a hot polymer through a nozzle suffers from an effect called die swell where the extruded polymer diameter is larger than the nozzle diameter (see figure below); decreasing the multiplier counteracts this effect.

Now your extruder and slicer should be optimally fine-tuned!