480

I'm designing a database table and asking myself this question: How long should the firstname field be?

Does anyone have a list of reasonable lengths for the most common fields, such as first name, last name, and email address?

5

13 Answers 13

401

I just queried my database with millions of customers in the USA.

  • The maximum first name length was 46. I go with 50. (Of course, only 500 of those were over 25, and they were all cases where data imports resulted in extra junk winding up in that field.)

  • Last name was similar to first name.

  • Email addresses maxed out at 62 characters. Most of the longer ones were actually lists of email addresses separated by semicolons.

  • Street address maxes out at 95 characters. The long ones were all valid.

  • Max city length was 35.

This should be a decent statistical spread for people in the US. If you have localization to consider, the numbers could vary significantly.

12
  • 4
    Compared to yours, the databases I have access to are tiny, but even there I found an email address of 138 characters. The localpart component is obviously some sort of LDAP (or AD?) distinguished name. Mar 10, 2011 at 15:54
  • 14
    The average lengths of email addresses in your database is not a good measure for recommendation. The maximum valid length of an email address is 254 chars and should be the length specified in the database. Additionally having lists of email addresses in a single column signifies to me that your data is not normalized and thus invalidates your answer further.
    – Mario
    Sep 26, 2016 at 13:48
  • 2
    @Mario, if you think about it though, most software that uses emails for logins, for example, probably shouldn't allow ridiculously impractical email addresses. See discussion here stackoverflow.com/questions/1297272
    – MGOwen
    Oct 27, 2017 at 3:50
  • 4
    Longest city name is 'Taumatawhakatangi­hangakoauauotamatea­turipukakapikimaunga­horonukupokaiwhen­uakitanatahu' coming in at 85 characters. en.wikipedia.org/wiki/List_of_long_place_names Apr 5, 2018 at 14:01
  • 5
    @binarysubstrate Actually, the longest city name is Krung Thep Mahanakhon Amon Rattanakosin Mahinthara Yuthaya Mahadilok Phop Noppharat Ratchathani Burirom Udomratchaniwet Mahasathan Amon Piman Awatan Sathit Sakkathattiya Witsanukam Prasit (AKA "Bangkok") clocking in at a length of 187 characters. Jun 22, 2018 at 20:46
190

UK Government Data Standards Catalogue details the UK standards for this kind of thing. It suggests 35 characters for each of Given Name and Family Name, or 70 characters for a single field to hold the Full Name, and 255 characters for an email address. Amongst other things..

7
  • 3
    The link needs to be updated as of Oct 22, 2010. I googled for: site:*.gov.uk Name "35 characters" and found this doc justice.gov.uk/guidance/docs/electoral-reg-standards.pdf
    – Tony R
    Oct 22, 2010 at 20:03
  • 26
    Just a thought... shouldn't it be 71 characters for the first and last name in a single field, given that there needs to be a space? Nov 17, 2011 at 19:04
  • 9
    Well, clearly they anticipate the occasional long forename (up to 35 characters) and the occasional long surname (up to 35 characters), but do not necessarily expect an individual with a combination of both lengthy forename and surname. That would just be greedy ;-)
    – Ian Nelson
    Sep 18, 2012 at 20:12
  • 7
    If Mr El Tahir El Fadil El Siddig Abderrahman Mohammed Ahmed Abdel Karim El Mahdi actually uses all his names when filling in online forms I would be impressed. I have two middle names but I only ever use one of them apart from on official (i.e. government) forms.
    – Leon
    Nov 20, 2015 at 8:30
  • 5
    @ian-nelson Email length according to RFC 3696: That limit is a maximum of 64 characters (octets) in the "local part" (before the "@") and a maximum of 255 characters (octets) in the domain part (after the "@") for a total length of 320 characters. Systems that handle email should be prepared to process addresses which are that long, even though they are rarely encountered. Dec 4, 2015 at 11:22
77

W3C's recommendation:

If designing a form or database that will accept names from people with a variety of backgrounds, you should ask yourself whether you really need to have separate fields for given name and family name.

… Bear in mind that names in some cultures can be quite a lot longer than your own. … Avoid limiting the field size for names in your database. In particular, do not assume that a four-character Japanese name in UTF-8 will fit in four bytes – you are likely to actually need 12.

https://www.w3.org/International/questions/qa-personal-names

For database fields, VARCHAR(255) is a safe default choice, unless you can actually come up with a good reason to use something else. For typical web applications, performance won't be a problem. Don't prematurely optimize.

2
  • 58
    It’s been 10 years since I asked that question. With another 10 years of experience under my belt, I’m inclined to agree with you. Sep 15, 2018 at 18:04
  • 7
    How exactly would you print a name that is 255 characters long on an envelope? Nov 10, 2018 at 4:44
72

Some almost-certainly correct column lengths

                            Min Max

Hostname                    1   255
Domain Name                 4   253
Email Address               7   254
Email Address [1]           3   254
Telephone Number            10  15      
Telephone Number [2]        3   26  
HTTP(S) URL w domain name   11  2083        
URL [3]                     6   2083    
Postal Code [4]             2   11
IP Address (incl ipv6)      7   45
Longitude                   numeric 9,6
Latitude                    numeric 8,6
Money[5]                    numeric 19,4

[1] Allow local domains or TLD-only domains
[2] Allow short numbers like 911 and extensions like 16045551212x12345
[3] Allow local domains, tv:// scheme
[4] http://en.wikipedia.org/wiki/List_of_postal_codes. Use max 12 if storing dash or space
[5] http://stackoverflow.com/questions/224462/storing-money-in-a-decimal-column-what-precision-and-scale

A long rant on personal names

A personal name is either a Polynym (a name with multiple sortable components), a Mononym (a name with only one component), or a Pictonym (a name represented by a picture - this exists due to people like Prince).

A person can have multiple names, playing roles, such as LEGAL, MARITAL, MAIDEN, PREFERRED, SOBRIQUET, PSEUDONYM, etc. You might have business rules, such as "a person can only have one legal name at a time, but multiple pseudonyms at a time".

Some examples:

names: [
  {
    type:"POLYNYM",
    role:"LEGAL",
    given:"George",
    middle:"Herman",
    moniker:"Babe",
    surname:"Ruth",
    generation:"JUNIOR"
  },
  {
    type:"MONONYM",
    role:"SOBRIQUET",
    mononym:"The Bambino" /* mononyms can be more than one word, but only one component */
  },
  {
    type:"MONONYM",
    role:"SOBRIQUET",
    mononym:"The Sultan of Swat"
  }
]

or

names: [
  {
    type:"POLYNYM",
    role:"PREFERRED",
    given:"Malcolm",
    surname:"X"
  },
  {
    type:"POLYNYM",
    role:"BIRTH",
    given:"Malcolm",
    surname:"Little"
  },
  {
    type:"POLYNYM",
    role:"LEGAL",
    given:"Malik",
    surname:"El-Shabazz"
  }
]

or

names:[
  {
    type:"POLYNYM",
    role:"LEGAL",
    given:"Prince",
    middle:"Rogers",
    surname:"Nelson"
  },
  {
    type:"MONONYM",
    role:"SOBRIQUET",
    mononym:"Prince"
  },
  {
    type:"PICTONYM",
    role:"LEGAL",
    url:"http://upload.wikimedia.org/wikipedia/en/thumb/a/af/Prince_logo.svg/130px-Prince_logo.svg.png"
  }
]

or

names:[
  {
    type:"POLYNYM",
    role:"LEGAL",
    given:"Juan Pablo",
    surname:"Fernández de Calderón",
    secondarySurname:"García-Iglesias" /* hispanic people often have two surnames. it can be impolite to use the wrong one. Portuguese and Spaniards differ as to which surname is important */
  }
]

Given names, middle names, surnames can be multiple words such as "Billy Bob" Thornton, or Ralph "Vaughn Williams".

5
  • 15
    This is very informative but not a super useful answer. The next time I need a "probably correct" answer I'll let you know.
    – n8bar
    Apr 27, 2016 at 0:31
  • 1
    I know this is an old answer and it might've been personal taste in the end, but can you speak to why you chose to cap Postal Codes at 11 when the longest postal codes in the world (U.S. & Iran) are 10 characters? I'm coming up with my own schemas for school assignments and I can't come up with a good argument to exceed 10 characters beyond maybe future-proofing. Oct 3, 2021 at 0:47
  • @DavidMetcalfe I see Ghana with 12 chars, incl dash Oct 3, 2021 at 5:32
  • @NeilMcGuigan So where does your case for 11 come in if Ghana exceeds it at 12? Are you always storing these codes without hyphens? Oct 3, 2021 at 17:31
  • @DavidMetcalfe see "Use max 12 if storing dash or space" Oct 3, 2021 at 18:30
17

I would say to err on the high side. Since you'll probably be using varchar, any extra space you allow won't actually use up any extra space unless somebody needs it. I would say for names (first or last), go at least 50 chars, and for email address, make it at least 128. There are some really long email addresses out there.

Another thing I like to do is go to Lipsum.com and ask it to generate some text. That way you can get a good idea of just what 100 bytes looks like.

3
  • 6
    Oh my - the first person to note that larger fields don't necessarily mean more storage space, hence the "var" in varchar. NVarchar would usually make more sense for names though.
    – Tao
    Jul 16, 2010 at 7:48
  • Depends on the implementation. You don't need NVARCHAR if VARCHAR supports UTF-8.
    – dan04
    Dec 22, 2010 at 7:10
  • 2
    [N]Varchar sizes do however, affect your indexes. Nov 7, 2013 at 22:37
11

I pretty much always use a power of 2 unless there is a good reason not to, such as a customer facing interface where some other number has special meaning to the customer.

If you stick to powers of 2 it keeps you within a limited set of common sizes, which itself is a good thing, and it makes it easier to guess the size of unknown objects you may encounter. I see a fair number of other people doing this, and there is something aesthetically pleasing about it. It generally gives me a good feeling when I see this, it means the designer was thinking like an engineer or mathematician. Though I'd probably be concerned if only prime numbers were used. :)

1
  • 4
    It is arguable that 2ⁿ - 1, 2ⁿ - 2 or even 2ⁿ - 4, two would be a better engineering decision because often strings are represented as zero-indexed character arays and terminated with a null char, byte or two bytes (UTF-8). Also with some databases going above 255 on a varchar requires an additional byte for storage (see stackoverflow.com/questions/2340639/…).
    – Pocketsand
    May 19, 2016 at 13:40
8

These might be useful to someone;

youtube max channel length = 20
facebook max name length   = 50
twitter max handle length  = 15
email max length           = 255 

http://www.interoadvisory.com/2015/08/6-areas-inside-of-linkedin-with-character-limits/

4

I wanted to find the same and the UK Government Data Standards mentioned in the accepted answer sounded ideal. However none of these seemed to exist any more - after an extended search I found it in an archive here: http://webarchive.nationalarchives.gov.uk/+/http://www.cabinetoffice.gov.uk/govtalk/schemasstandards/e-gif/datastandards.aspx. Need to download the zip, extract it and then open default.htm in the html folder.

0
4
+------------+---------------+---------------------------------+
|   Field    | Length (Char) |           Description           |
+------------+---------------+---------------------------------+
|firstname   | 35            |                                 |
|lastname    | 35            |                                 |
|email       | 255           |                                 |
|url         | 60+           | According to server and browser |
|city        | 45            |                                 |
|address     | 90            |                                 |
+------------+---------------+---------------------------------+

Edit: Added some spacing

2
  • 1
    Why not just use VARCHAR 255 for everything that is a string? VARCHAR does not use padding and terminates with an additional one or two bytes.
    – radtek
    Feb 3, 2016 at 20:26
  • varchar could be a little bit slow.
    – kta
    Nov 19, 2019 at 5:04
2

Just looking though my email archives, there are a number of pretty long "first" names (of course what is meant by first is variable by culture). One example is Krishnamurthy - which is 13 letters long. A good guess might be 20 to 25 letters based on this. Email should be much longer since you might have firstname.lastname@somedomain.com. Also, gmail and some other mail programs allow you to use firstname.lastname+sometag@somedomain.com where "sometag" is anything you want to put there so that you can use it to sort incoming emails. I frequently run into web forms that don't allow me to put in my full email address without considering any tags. So, if you need a fixed email field maybe something like 25.25+15@20.3 in characters for a total of 90 characters (if I did my math right!).

1
  • A top level domain can be more than 3 characters. So only 3 characters for TLD is not a safe calculation in these modern times. So to be on the safe side: I'd suggest taking at least 32 characters for TLD in consideration (max is 63 characters I believe). In this case: I'd suggest using at least 128 characters for email fields, preferably over 160 characters.
    – Tommie
    Feb 3, 2021 at 9:13
1

I usually go with:

Firstname: 30 chars
Lastname: 30 chars
Email: 50 chars
Address: 200 chars

If I am concerned about long fields for the names, I might sometimes go with 50 for the name fields too, since storage space is rarely an issue these days.

1
  • 13
    50 for email? 254 is the maximum actually
    – Marko
    May 3, 2012 at 2:56
0

If you need to consider localisation (for those of us outside the US!) and it's possible in your environment, I'd suggest:

Define data types for each component of the name - NOTE: some cultures have more than two names! Then have a type for the full name,

Then localisation becomes simple (as far as names are concerned).

The same applies to addresses, BTW - different formats!

-2

it is varchar right? So it then doesn't matter if you use 50 or 25, better be safe and use 50, that said I believe the longest I have seen is about 19 or so. Last names are longer

Not the answer you're looking for? Browse other questions tagged or ask your own question.