There are two criteria to differ between flexion and extension:
1) Decreasing or increasing the angle between the involved bones. By this criteria, it should be clear that flexion means bending of the elbows and knees and lateral bending of the spine (the neck and torso) toward the bent side.
2. The anterior/posterior direction of the movement. All anterior (ventral) movements in the neck or torso part of the spine, shoulder, elbow, wrist, fingers, hip, ankle and toes are called flexion and all posterior (dorsal) movements (except in the knee) are called extension.
You should not use the both criteria at the same time, because they can contradict each other.
There are some specifics:
- In the wrist, you can have palmar flexion, dorsiflexion (extension), ulnar flexion (abduction) and radial flexion (adduction) (Teachmeanatomy).
- In the ankle, you can have plantar flexion, dorsiflexion (extension), inversion (inward rotation, adduction) and eversion (outward rotation, abduction). (ScienceDirect).
- In the shoulder and hip, raising a limb to the same side as the limb is, is abduction (lateral extension) and raising it to the opposite side is adduction.
- Moving the thumb toward the palm (in the same plane as palm) is flexion (adduction) and moving it away from it is extension (abduction).
You can read about flexion and extension and other movements here: Types of Body Movements (BCcampus)
Flexion and extension are movements that take place within the
sagittal plane and involve anterior or posterior movements of the body
or limbs. For the vertebral column, flexion (anterior flexion) is an
anterior (forward) bending of the neck or body, while extension
involves a posterior-directed motion, such as straightening from a
flexed position or bending backward. Lateral flexion is the bending of
the neck or body toward the right or left side.
In the limbs, flexion decreases the angle between the bones (bending
of the joint), while extension increases the angle and straightens the
joint. For the upper limb, all anterior-going motions are flexion
and all posterior-going motions are extension. These include
anterior-posterior movements of the arm at the shoulder, the forearm
at the elbow, the hand at the wrist, and the fingers at the
metacarpophalangeal and interphalangeal joints. For the thumb,
extension moves the thumb away from the palm of the hand, within the
same plane as the palm, while flexion brings the thumb back against
the index finger or into the palm. These motions take place at the
first carpometacarpal joint. In the lower limb, bringing the thigh
forward and upward is flexion at the hip joint, while any
posterior-going motion of the thigh is extension. Note that
extension of the thigh beyond the anatomical (standing) position is
greatly limited by the ligaments that support the hip joint. Knee
flexion is the bending of the knee to bring the foot toward the
posterior thigh, and extension is the straightening of the knee.
Flexion and extension movements are seen at the hinge, condyloid,
saddle, and ball-and-socket joints of the limbs (see Figure 1).
Now, to answer the question about the goniometer.
Again, the confusion about interpretation of this goniometer arises from two different criteria about flexion. The one mentioned in the Wikipedia and other anatomical articles says that in flexion the angle between the involved bones decreases. When you raise your arm, this criteria does not aply because the angle between the bones (humerus/scapula) in the shoulder joint does not really change (unlike in the elbow, for example), so here the criteria that all anterior movements are considered flexion applies. When you have an arm straight down, there is no flexion, so it's considered zero degrees and when it's straight up, it's considered 180 degrees, so the angle is increasing, but this is not an angle between the arm and other bones or the body but between the starting and ending position of the arm.