A gap penalty is a (typically negative) cost score that is assigned to a gap in an alignment.

Gap penalties come in three main forms. First, a gap penalty may be constant, in which case we charge a fixed cost for the gap. Secondly, a gap penalty may be linear, in which we charge a fixed cost for every inserted or deleted symbol, so that the gap is charged by a penalty that is directly proportional to the length of the gap.

An affine gap penalty blends the two previous penalty types by charging one constant penalty (the gap opening penalty) for the first symbol of a gap and another constant penalty (the gap extension penalty) for each additional inserted or deleted symbol in the gap.