Trim is a way to make a small but constant and continuous adjustment to a control surface on an aircraft. Control surfaces are the things that make the aircraft pitch, roll, and yaw: the elevators, ailerons and rudder, respectively.

To understand how trim works it's first useful to understand how wings and control surfaces work.

Wings work largely off the principle described by Newton's third law of motion: for every action there is an equal and opposite reaction. They also utilise the coanda effect, which is the tendency of jets of fluid substances (of which air is one) to follow the contours of surfaces they are in contact with. Hold the underneath of the head of a spoon next to a stream of water from a tap to see this for yourself.

A wing is shaped in such a way that air flowing over it is deflected downwards; in doing so, the wing itself is forced upwards. Fine.

Control surfaces change the shape of the surfaces they are attached to, altering the way those surfaces deflect air flowing over them. Take elevators, for instance, which control aircraft pitch. They are mounted on an aircraft's tailplane, aka horizontal stabiliser.

When the elevators move up or down, they change the way that the tailplane deflects air. When they are flat, the tailplane probably has relatively little effect on air flowing over it. When they are moved upwards, they deflect air flowing over them upwards. In doing so the tailplane, which they are attached to, is forced downwards. So the aircraft tail moves downwards. But the aircraft itself doesn't move downwards, it pivots around its center of gravity. So while the tail pivots downwards, the nose pivots upwards and the aircraft, if it's going fast enough, will climb.

Conversely if the elevators move down, they deflect air downwards. The elevators and thus the tail of the aircraft are forced upwards, its nose pitches downwards, and the aircraft descends.

Now we can get to trim. To understand trim, simply think of the control surfaces as wings in themselves. Trim is the control surface of a control surface. Let's use the elevator again as an example:

---------====+++
'-' is the tailplane. '=' is the elevator, and '+' is the trim tab. If the trim tab moves upwards:
               +
              +
---------====+
...(exaggerated, of course) it deflects air upwards. This causes it, and the elevator it is attached to, to be forced downwards:
---------=
          =
           =
            =+++

So, when the trim tab moves upwards, it causes a downward pitch moment. The effect of the trim tab's movement on aircraft pitch is the opposite of the same movement by the elevators.

Trim tabs are typically controlled using a small wheel in the cockpit—one for each set of control surfaces—that are used to dial up a specific setting. That setting then remains until it is changed, unlike the main control surfaces, which in flight tend to return to 'neutral', or flat, positions if the pilot lets go of the control yoke.

Trim is used to apply a constant force to a control surface, without the pilot having to do it using the main control yoke. If an aircraft's weight balance means it tends to pitch up slightly in flight, the pilot can adjust the elevator trim to give a slight downward pitch moment, and level out the aircraft's pitch behaviour without having to apply constant pressure to the control yoke themselves. Trim may be available for the rudder and ailerons depending on the aircraft, but is always present for the elevators.