Unlike 1D codes where all information can be found in one cut through the code, 2D codes need a second dimension since they contain many different ‘lines’ of data. Among the most popular 2D codes are the QR codes and Data Matrix. QR code was created by Denso Wave in 1994 and Data Matrix was invented by ID Matrix around 2005. The Data Matrix that is in popular use is the EC200 (there are other variations less popular). Both can be used free of any licensing or royalties, and hence their popularity. In this post I would like to compare these two codes and see when one of them might be more suitable to use than the other.
Both codes contain areas of data and recognition areas that helps to detect the code and inform the decoder how to decode it (like version, masks etc). Both of them use the Reed Solomon system to recover damaged part of the code data. Here are typicals QR code and Data Matrix with their non-data areas marked in red.
From first sight it is quite obvious that QR codes has more recognition area than Data Matrix (which uses only its perimeter for this purpose). The Data Matrix to the right uses only 84 modules of its 22×22 modules (17%) as recognition area, while the QR code to the left uses 228 modules of its 29×29 (27%) as recognition area. It means that Data Matrix has 10% more of its area available for data and hence they are more compact in size and more effective – using less area to contain same amount of data.
When this may be the situation in few cases, it is not always so. Let’s see why and when one of these codes is more appropriate to use than the other.
Versions and recognition data
Both QR codes and Data Matrix modules will grow by steps as data is added. These steps create what is called versions of the codes. For QR code the smallest possible version has 21×21 modules, when Data Matrix smallest version is 10×10 modules. QR codes grow in steps of 4 modules in each direction for every version until its final version 40 which is 177×177 modules. Data Matrix grows in steps of 2 modules in each direction with some gaps and even few rectangular codes where the number of modules in each direction is different. Its largest size has 144×144 modules.
QR codes add an overhead of a fixed size (the finder patterns) and a varying size (the time lines) that grows with the version of the QR code. The overhead area of Data Matrix on the other hand is totally dependent on its version. It is should be easy than to see when QR codes will become more effective in data/area ratio.
QR code overhead is:
7x7x3 (the finder patterns)
5×5 (the guiding pattern)
29 modules – the version and mask information
2(L – 14) – the timelines (where L is the number of modules in each direction)
Data Matrix overhead is 4L-4 (where L is the number of modules in each direction)
To see when QR codes overhead area will be smaller than Data Matrix overhead area we have to find the smallest L that fits into the following equation 4L-4 > 7x7x3 + 5×5 +29 +2L-28
This starts happening when L is 89 modules. For QR code it means version 18. Version 18 can contain 721 characters or more than 1900 digits. For example a typical business card contain between 60-150 characters, which means that Data Matrix is more suited for business cards than QR codes.
Here is a QR code with some contact data and a Data Matrix with exactly the same data.
The QR code has 37×37 modules (version 5) while the Data Matrix has 40×40 modules.
Surprise! How is this possible? It is truth that 2 additional lines of recognition area were added to the Data Matrix (the vertical and horizontal lines in the center) but still the Data Matrix should have been with much less modules than the QR code.
The reason for this resides in the Error Correction levels. The EC of all Data Matrix in all versions is around 30% when QR codes have 4 different EC levels. The QR code in the left has only 7% additional data area for EC while the Data Matrix has 30% additional data for EC. The additional 23% cause the Data Matrix to be larger than the QR code at the end.
When Data Matrix may be the better choice
1- The lowest version of Data Matrix is 10×10 modules, so whenever you are tight in print area and your encoded message is short enough to go into a 10×10 to 20×20 Data Matrix – go for Data Matrix.
2- Whenever you need to put your logo or any other image on your 2D code, and printing size matters – consider Data Matrix.
Here are the same codes as above with a logo in the maximum possible size for each of them.
The only reason for the difference in logo size is the Error Correction level. Same size of logo will work for a QR code with a High Error Correction (30%) – only the QR code version will be higher and therefore with a bigger print area.
Note: It is not a good idea to use all of EC power when drawing on a 2D code. You should always leave some extra safe zone for unexpected damage to the code or to the images that will reach decoders.
When QR codes may be a better choice
1- Whenever you are tight in print area and your encoded message goes into a Data Matrix of size 22×22 or more go for QR codes with a low or medium EC.
2- Whenever the esthetic of your code matters, QR codes have an advantage over the Data Matrix due to their finding patterns and general look. For some reason decorated QR codes look better than decorated Data Matrix.
3- QR codes has few modes of encoding data, some of them are more compact than the 8 bits for character used by Data Matrix. In situation when an encoding mode with low EC gives you a smaller print area, go for the QR code.
Readers for Data Matrix
Many readers that support QR codes support also Data Matrix.
Here is a list of these readers.
For Android devices you can find also – Barcode Scanner, wBarCodesList, ixMat, BaroScan
By the way – I’m sure there are other readers for Data Matrix that I am not aware of.