iTranslated by AI
The Inner Workings of Barcodes
What is a Barcode
A symbol that represents numerical values through the thickness of striped lines, also known as a 1D code.
Barcode standards are global, but the specific standard used in Japan is called the JAN code. [1]

Example of a JAN code
JAN Code
The standard type consists of 13 digits, while the shortened type consists of 8 digits.
Furthermore, the standard type is divided into those with a 7-digit or 9-digit manufacturer code; for 7 digits, the product code is 5 digits, and for 9 digits, the product code is 3 digits.
For both standard and shortened types, the first two digits are the country code (47 or 49 in Japan), and the last digit is the check digit.

From Barcode Course
Structure of JAN Code

From Barcode Course
JAN codes are represented by bits of 0 and 1. 0 is white and 1 is black.
The constituent elements include guard bars, data characters, and a check digit.
I will explain each of these below.
Guard Bars
The bars in the barcode that protrude slightly downwards are called guard bars.
These indicate the beginning, end, and middle of the barcode.
They are represented by 101, 01010, and 101, respectively.
Data Characters
In the standard type, 6 characters are stored to the left of the center bar and 5 characters to the right.
Numerical values are converted according to the table below.
Even and odd parity[2] are taken into account when determining the first digit.
| Value | Left Odd Parity | Left Even Parity | Right Even Parity |
|---|---|---|---|
| 0 | 0001101 | 0100111 | 1110010 |
| 1 | 0011001 | 0110011 | 1100110 |
| 2 | 0010011 | 0011011 | 1101100 |
| 3 | 0111101 | 0100001 | 1000010 |
| 4 | 0100011 | 0011101 | 1011100 |
| 5 | 0110001 | 0111001 | 1001110 |
| 6 | 0101111 | 0000101 | 1010000 |
| 7 | 0111011 | 0010001 | 1000100 |
| 8 | 0110111 | 0001001 | 1001000 |
| 9 | 0001011 | 0010111 | 1110100 |
The first digit of the standard type is determined by the combination of odd and even parity, as shown in the table below.
For the shortened type, all digits use odd parity.
| 1st Digit | Combination of Odd (O) and Even (E) |
|---|---|
| 0 | OOOOOO |
| 1 | OOEOEE |
| 2 | OOEEOE |
| 3 | OOEEEO |
| 4 | OEOOEE |
| 5 | OEEOOE |
| 6 | OEEEOO |
| 7 | OEOEOE |
| 8 | OEOEEO |
| 9 | OEEOEO |
In other words, a JAN code such as 1234567890123 for the standard type is converted as follows:
Since it is a standard type, determine the combination of odd and even parity for the 1st digit. In this case, it is 1, so according to the table above, the combination is OOEOEE.
Determine the 2nd to 6th digits based on the calculated combination of odd and even parity using the table above.
The 2nd digit is 2 with odd parity, so it becomes 0010011. Similarly, the 3rd digit is 3 with odd parity, so it is 0111101, and the 4th digit is 4 with even parity, so it is 0011101, and so on.
Since only even parity is defined for the right side, convert them according to the table.
Check Digit
The last digit of a JAN code is a check digit[3] used to determine the correctness of the reading result.
The check digit is calculated as follows:
| Digit Number | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Barcode | 4 | 9 | 3 | 3 | 0 | 3 | 2 | 0 | 1 | 0 | 5 | 7 | 9 |
-
Add all the numbers in the even-numbered positions and multiply the result by 3.
(9+3+3+0+0+7)×3=66 -
Add all the numbers in the odd-numbered positions, excluding the last digit which is the check digit.
(4+3+0+2+1+5)=15 -
Add the results of steps 1 and 2.
66+15=81 -
Subtract the remainder of the result of step 3 divided by 10 from 10. The result is the check digit.
However, if the remainder of step 3 divided by 10 is 0, the check digit is 0.(10-(81\%10))\%10=9
In this case, the calculation result is 9, which matches the value of the last digit (the check digit), so the reading result is considered correct.
Generating JAN Codes
By following the above procedure, converting the JAN code 4933032010579 results in the following:
| Left Guard Bar | 1st Digit | 2nd Digit | 3rd Digit | 4th Digit | 5th Digit | 6th Digit | Center Bar | 7th Digit | 8th Digit | 9th Digit | 10th Digit | 11th Digit | Check Digit | Right Guard Bar |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 101 | 0001011 | 0100001 | 0111101 | 0001101 | 0100001 | 0011011 | 01010 | 1110010 | 1100110 | 1110010 | 1001110 | 1000100 | 1110100 | 101 |
By coloring the 1s black and the 0s white, the JAN code is complete.

Conclusion
Personally, I found it interesting that the first digit is represented by a combination of odd and even parity.
By the way, I created a Python library for generating JAN codes, so please feel free to try it out 😊
The source code is available here:
References
Discussion