Capping of the pre-mRNA involves the addition of 7-methylguanosine (mG) to the 5 end. To achieve this, the terminal 5 phosphate requires removal, which is done with the aid of enzyme RNA triphosphatase. The enzyme guanosyl transferase then catalyses the reaction, which produces the diphosphate 5 end. The diphosphate 5 end then attacks the alpha phosphorus atom of a GTP molecule in order to add the guanine  residue in a 55 triphosphate link. The enzyme (guanine-N-)-methyltransferase ("cap MTase") transfers a methyl group from S-adenosyl methionine to the guanine ring. This type of cap, with just the (mG) in position is called a cap 0 structure. The ribose of the adjacent nucleotide may also be methylated to give a cap 1. Methylation of nucleotides downstream of the RNA molecule produce cap 2, cap 3 structures and so on. In these cases the methyl groups are added to the 2' OH groups of the ribose sugar.
The cap protects the 5 end of the primary RNA transcript from attack  by ribonucleases that have specificity to the 35' phosphodiester bonds.