Windows includes a DLL called pidgenx.dll
which includes this function:
[DllImport("pidgenx.dll", EntryPoint = "PidGenX", CharSet = CharSet.Auto)]
static extern int PidGenX(string productKey, string pkeyPath, string mspid, int unknownUsage, IntPtr productID, IntPtr digitalProductID, IntPtr digitalProductID4);
For pkeyPath Windows setup passes a path to pkeyconfig.xrm-ms. In this file, the product key are defined and in the digitalProductID4 (last parameter), the Edition and Product key type (MSDN, Retail, Trial) is encoded.
The Ultimate PID Checker is one of several tools that call the function to decode the key.
Here you can see which edition the key belongs to.