11

I'm writing some attendance software. Each member will have an ID card with a barcode which they will use to sign in to events. How long should the barcode field be in my database? I'd like to accept Code 39 and Code 128 barcodes. I know these are variable length codes, so what should I set the max length to?

Thanks!

EDIT: My clients will be using a variety of third-party barcode printing tools.

bestattendance
  • 26,382
  • 5
  • 25
  • 24

5 Answers5

11

There are no constraints on the general Code 128 symbology, but for example, one of application specifications (GS1) sets practical limits:

GS1-128 barcode size characteristics:

  • The maximum physical length is 165.10 millimetres (6.500 inch) including Quiet Zones.
  • The maximum number of data characters in a single symbol is 48.

GS1 General Specifications section 5.4.1: "GS1-128 symbology characteristics".

An example demonstrating size constrains for Code 128 is provided in this answer.

Terry Burton
  • 2,801
  • 1
  • 29
  • 41
guest
  • 111
  • 1
  • 2
6

These formats can easily encode plenty of digits, surely more than you need for a unique ID. So isn't the question merely, how long are your IDs? Is 10 digits plenty? then 10 characters. Or if they're numeric IDs, you shouldn't even store as a string of characters. Use a numeric SQL type.

Sean Owen
  • 66,182
  • 23
  • 141
  • 173
5

Code 128 can do 128 ASCII characters so set the max length to 128 (or higher, it doesn't really matter).

Let me clarify that last statement. Variable text fields will use 1 byte per character (or more for Unicode type fields but let's ignore those for now) plus some overhead. That overhead might be as little as 1-4 bytes or as much as 16 or more depending on the database.

But the point is that if you store 100 characters in a VARCHAR(128) field or a VARCHAR(1000) field it still uses the exact same amount of space.

The only issue you run into is row limits. This too is database dependent. On some for example the entire row can only take up to 64K in size so the sum of all sizes can't exceed that. Other than that it doesn't matter.

cletus
  • 616,129
  • 168
  • 910
  • 942
  • 14
    Correct me if I am wrong, but this [wiki article](http://en.wikipedia.org/wiki/Code_128) says that Code 128 can encode all of the 128 ascii characters, not that is is 128 characters long. The barcodes in our DBs are 25 chars long and we have not had any complaints. – tkerwood Oct 25 '13 at 06:31
  • 1
    @tkerwood you're right. Code128 is not the limit to the number of characters, but is the character set that can be encoded. The rest of this answer, re: varchar size in the database is correct. – Sean Nov 20 '13 at 15:59
  • 2
    Now there are [too many doubts](http://stackoverflow.com/questions/2660560/barcode-field-length/2660568#comment29063478_2660568) (including mine) about 128 character limit. So maybe it is time to correct your statement or provide a source for that 128 character limit. – miroxlav Oct 09 '15 at 22:27
  • There's already explanation in https://stackoverflow.com/a/21390093/1449366 - CODE-128 is not limited in length per se, but its implementations may be. – AnrDaemon Nov 02 '22 at 12:41
0

The data limit of a Code 128 barcode is 48 Characters.

https://www.premierelectronics.com/blog/barcode-types-identificaton-understanding#accordion-3

Tom S
  • 1
-3

Code 39 is restricted to 43 characters. In Full ASCII Code 39 Symbols 0-9, A-Z, ".", "-" and space are the same as their representations in Code 39.