The ‘CIGAR’ (Compact Idiosyncratic Gapped Alignment Report) string is how the SAM/BAM format represents alignments.
Understanding the different CIGAR strings (eg: “6M”, “3M2I3M”, in the examples below) will help you to understand how the query (or “read”) sequence aligns to the reference genome.

CIGAR strings have several operators, each preceded by a number, p the number of aligned nucleotides

The position stored is the left-most coordinate of the aligned query to the genomic reference-position. To determine the final coordinate of the aligned query, you have to parse the CIGAR string.
Here are five different concrete examples:
First example: The shown alignment will give position = 2 (0-based!) and CIGAR = 6M
This means there are 6 exact matches to the reference. So if we are starting at position=2, with 6 exact matches, we end at reference-position 7 (again 0-based)
Second example: The shown alignment, will give position=2 (0-based) and CIGAR=3M2I3M:

Here, two nucleotides (‘GA’) are inserted into the query. So if we are starting at position=2, based on the CIGAR string, we have 3 exact matches, 2 insertions, then 3 more exact matches, resulting in an end reference-position of 9.
Third example: The shown alignment will give position=2 and CIGAR=1M2X3M:

Here, two nucleotides (‘AA’) replace the original two (‘TC’) of the first example and do not match the reference. So if we are starting at position=2, based on the CIGAR string, we have 1 exact match, 2 mismatches (or substitutions), then 3 more exact matches, resulting in an end genomic-position of 7.
Fourth example: The shown alignment will give position=2 and CIGAR=2M1D3M:

Note there is a deletion on the query. The ‘C’ in the reference sequence has no match. So if we are starting at position=2, based on the CIGAR string, we have 2 exact matches, 1 deletion, then 3 more exact matches, resulting in an end position of 7 relative to the reference.
Fifth example: The shown alignment will give position=3 and CIGAR=3M7N4M:

This is a gapped alignment (due to a splicing event in RNAseq). So if we are starting at position=3, based on the CIGAR string, we have 3 exact matches, 7 gaps*, then 4 more exact matches, resulting in an end position of 16.
*While equivalent to a deletion, a gap, N is reserved for nucleotides known in the reference that are absent in the query due to a splicing event. In other words: when aligning the intron sequence of the reference to the spliced query.
The “delins” concept
A delins is simply described as a combination of a deletion and insertion at a given locus. When explaining this same concept applied to SPDI annotation, NCBI states:
To clarify, using the term “deleted sequence” does not imply that someone is asserting that the mechanism behind the variant was a deletion then an insertion. It only specifies that the same variant sequence would be observed, if this deletion followed by this insertion was applied to the reference sequence.”
A delins variant definition will appear in a CIGAR string as a deletion, followed by an insertion eg, the 8D4I here:
>frg400 15M8D4I7M1X7M2X5M1X158M
CATTGGAACAGAAAGagatTTATCTGtTGTTTGCagTGAAGgAGTACAAAATG
The reverse-complement of this sequence, and its corresponding CIGAR, looks like this:
>frg800 158M1X5M2X7M1X7M8D4I15M
CATTTTGTACTcCTTCActGCAAACAaCAGATAAatctCTTTCTGTTCCAATG
The delins sub-CIGAR 8D4I reads the same in both directions. The starting point refers to the last nucleotide before the insertion, so a mapped starting point will differ for all cases apart from 1DnI, where ‘n’ means any number.
Additional resources
With thanks for the original from JefWorks Lab and modified here, under terms of the Creative Commons Attribution 4.0 International License, primarily to include the mismatch symbol “X”, but with: a number of layout changes; word-edits; addition of an example; the delins section. Permission is given to reuse this version under the same terms.
NB: Usage statistics on this website show this page to be the single most-accessed item, at about 100-200 per month; courtesy of search-engine referrals!