Knowing how optical discs are manufactured is essential in understanding and interpreting matrix codes, which again can result in more information about various releases. This is not a detailed description of the process of optical disc production, but a short overview to understand how and when matrix codes are written into the discs.
Before the mastering stage can begin, the audio must be transferred to an image ready format. Now that means to CD-R, sometimes called gold master, but before they also used 8 mm tape. The image ready CD-R can be sent back to the record label to be tested and approved. 
A primer and a photoresistant coating is spin-coated evenly on a glass substrate, a round disc of polished glass, which is then baked at 110ºC for 30 minutes. The disc is placed inside the laser beam recorder (LBR), which records the digital information from the image ready CD-R into the dried photoresistant coating. This glass master is developed by spin-coating it with sodium hydroxide. It washes away the photoresistant coating whereever the laser beam touched, leaving tiny pits, or digital information. The developed glass master is placed in a vacuum chamber, and a thin layer of silver, only a few molecules thick, is deposited onto the disc. This is now called the metalized glass master (MGM), or the matrix. 
The MGM is then placed in a tank with nickel sulphamate solution, and a layer of nickel is grown on the silver. The resulting nickel plate, which is separated from the MGM, is a negative image of the MGM called the father, or sometimes the matrix. Just like with vinyl manufacturing, the father can be used to stamp discs, but if damaged, the entire mastering process would have to be restarted. Instead a mother, a positive image of the MGM, is created by depositing a new layer of nickel to the father. Negative images for production, stampers, are made by depositing a new layer of nickel on the mother. 
The stamper is mounted in a mould, and polycarbonate is injected into the mould and compressed and melted. The stamper moulds the pits into the plastic. The mould is cooled with water, and the plastic solidifies. Depending on the mould, this process takes 3-10 seconds for each disc. The disc is taken out of the mould, and a thin layer of aluminum is sputtered onto the side which contains the pits, creating the reflective metal layer. A protective coating, a thin layer of sealant or lacquer, is spin-coated onto the aluminum, and dried with UV light. Finally, the discs are printed, either with screen printing or offset printing. 
The various types of matrix and mould codes are shown in image 1. The digital part of the matrix code, including the LBR IFPI code which identifies the LBR in use, is recorded into the glass master by the LBR along with the music. Typically this will include the record label's catalog number, the pressing plant's internal reference number, and a number indicating the number of the glass master if several glass masters are made. There may also be a barcode. Some pressing plants put a lot of information in here, while some put very little.
For example, "G-6431" in the Sonopress matrix code in image 1 is the internal reference Sonopress gave the source of the contents they received by the record label, the master tape or master CD-R. "GED24504" identifies it as the German Incesticide release. The "C" may be related to the disc mastering process, in other words the MGM. A variant has "A1" instead. All the discs with "G-6431" are then sourced from the same music (master tape or CD-R), but mastered to several MGMs as indicated by the slight variants.
A more interesting example is the German Nevermind, also pressed by Sonopress. The first pressing is sourced from "F-5809", and was missing Endless, Nameless. The second pressing was sourced from a new master, "F-6493", but it was still missing the hidden song. Finally, pressings with "F6493-1" came with the song included. This indicates that the first master the plant received was missing the song entirely, a mistake on the record label's part. The second master had the song, but this time it was the pressing plant which failed to include it when they made the first MGM. The error must have been noticed, and resulting MGMs were made from the same source, but redone as indicated by the "-1".
Similar to for vinyl cuts, CD mastering engineers may also sometimes write "RE-1" and so on in the matrix codes to indicate a remake of an MGM if the previous attempt was unsuccessful.
1. Matrix and IFPI codes (Sonopress and Nimbus discs)
The stamper numbers are mechanically etched into the metal plates, so they look very different from the part of the matrix code written by the LBR. They are often written in dotted characters. Unlike with vinyl records, mechanical etchings can be done to all plates; fathers, mothers, and stampers. Discs with identical digital matrix codes but different stamper numbers still contain the same contents, as they come from the same master which is only identified by the digital part.
Some stamper numbers are shown in image 2. These numbers are etched to keep track of the various metal parts. In case there is an error with a pressing, they can trace it back to where it originated. If there are two numbers, such as SRC's "M1S1" or Nimbus' "1:4" as shown in image 2, the first number refers to the mother while the second refers to the stamper created from that mother. If there are three numbers, such as EMI's "1-1-1", the first number refers to the father.
The first matrix part shown in image 2 is a South African pressing of Nevermind (CDGEFL 20015). The pressing plant received metal plates from Sonopress which were sourced from the same MGM and father as the German pressings, but mechanically etched over "SONOPRESS". (Sonopress has their own pressing plant in South Africa, but they did not start up until 1996.)
2. Mechanical additions to matrix codes
IFPI codes, also known as SID codes (source identification), identify the source of optical disc mastering and manufacturing. There are two types of IFPI codes. The LBR IFPI has already been mentioned, and it identifies the particular LBR machine which was used to record the digital information onto the glass master. It always starts with an L followed by three, and later four, alphanumeric characters.  In most cases a disc is replicated by the same company which mastered it, but not always. In these cases, the LBR IFPI cannot identify which plant replicated the discs.
The mould IFPI is, as the name suggests, fitted to the mould which presses the disc, and as such is not a part of the matrix code. The code is very different to the matrix code, as it appears to have been carved into the plastic. In four-digit mould codes, the two first alphanumeric characters identify the pressing plant, while the latter identify the particular mould at this pressing plant. In five-digit mould codes, the three first characters identify the pressing plant. "IFPI 0717" then means that the disc was pressed in mould 17 by Sonopress in Germany. This can be used to trace errors, and to show that the pressing plant adheres to IFPI's anti-piracy guidelines, but IFPI codes can be faked. 
IFPI codes were first introduced in late 1993 according to an IFPI employee , but IFPI's website states 1994 . It seems that the actual implementation started some time in 1994. If your copy of Nevermind has an IFPI code, it is certainly not an original 1991 pressing. The Pennyroyal Tea single was probably manufactured around the time when Sonopress had started to fit IFPI codes to their moulds, as there are pressings both with and without mould IFPI codes. The existence of several mould IFPI variations, but identical matrix codes, suggests that the discs were pressed in different moulds more or less at the same time, and are not necessarily different pressings .