Two STANAG compatible magazines. Left is a 20 round magazine made by Colt, right is a 30 round "High Reliablility" magazine made by Heckler & Koch/
Click on image to enlarge.
Image licensed under GNU Free Documentation License v 1.2 or later, by user Raygun on wikipedia.
Back when NATO was first formed, they agreed to develop a set of common standards that all the member countries could use, in order to ensure that the various countries under the NATO umbrella could share arms and ammunition. These standards were called STANdardization AGreements, or STANAGs for short and many were published for various military hardware. We start our story in 1980, soon after NATO had standardized on using the NATO 5.56x45 mm. cartridge for their assault rifles. STANAG 4172 was the document that specified the standards for the NATO 5.56x45 mm. cartridge. Soon after this, STANAG 4179 was proposed, which described the standards for how the magazines were to be made. Now for the real amusing part: STANAG 4179 was a document containing a proposed standard for magazines, but was never officially accepted by all the member countries and therefore remains as a "Draft STANAG" to this date! Therefore, calling these magazines as "STANAG compatible magazine" is not technically correct.
Nevertheless, many manufacturers started making magazines to the standards proposed by the document, even before it was officially ratified. Some people are under the impression that the STANAG standard specifies the magazine capacity, along with the dimensions of the magazine, but this is an incorrect assumption to make. Even though most of the magazines made for military purposes are usually 20 or 30 round capacity, there exist other STANAG compatible magazines that hold 40, 50 or even 100 rounds. The shape can be different as well, as there are drum magazines and box magazines that are both STANAG compatible. The STANAG 4179 document only specifies some of the dimensions of the magazine and also doesn't specify the materials to be used or manufacturing standards. Therefore, different manufacturers can make the magazines to any length, with different kinds of material (e.g. aluminium, steel, plastic etc.), and still claim to be STANAG compatible. This causes production quality from various manufacturers to differ.
There are now many rifles that can take STANAG magazines, such as AR-15, M-16, Heckler and Koch G41, FAMAS G2, Tavor TAR-21 etc. and some other rifle models such as SIG 556, H&K G36, IMI Galil etc. can also use them with a magazine adapter.