487

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?

vvvvv
  • 25,404
  • 19
  • 49
  • 81
Patrick McElhaney
  • 57,901
  • 40
  • 134
  • 167
  • 3
    See ["Maximum length of a valid email id"](http://stackoverflow.com/questions/386294/maximum-length-of-a-valid-email-id) for maximum e-mail address length. – outis Apr 16 '11 at 17:50
  • What about URL, like blog or link to profile? – AlikElzin-kilaka Jan 14 '15 at 06:53
  • 1
    Screwed if the name is as long as this one http://gintama.wikia.com/wiki/Jugem_Jugem – 絢瀬絵里 Apr 10 '17 at 16:16
  • 2
    Just make sure you allow non-alpha characters in the names! *points at hyphen in his last name* – Chris Marasti-Georg Aug 21 '08 at 20:03
  • 4
    One note: don't require both a "first name" and a "last name". Some people, like me, only have one name. (Proof: https://web.archive.org/web/20130115074449/http://saizai.com/dl_redacted_small.png) – Sai Jul 08 '11 at 02:06

13 Answers13

405

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.

Patrick McElhaney
  • 57,901
  • 40
  • 134
  • 167
Eric Z Beard
  • 37,669
  • 27
  • 100
  • 145
  • 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. – Bernd Jendrissek Mar 10 '11 at 15:54
  • @EricZBeard Does "street address" include the house number? – noɥʇʎԀʎzɐɹƆ Jun 11 '15 at 00:26
  • 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 '16 at 13:48
  • same as @Mario. There is specification for email size http://www.dominicsayers.com/isemail/ – GeoStoneMarten Dec 16 '16 at 10:31
  • 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 https://stackoverflow.com/questions/1297272 – MGOwen Oct 27 '17 at 03:50
  • 1
    It's pretty clear when you actually look at it: *twohundredandfiftyfourcharactersislongerthanthis.howmanypeoplewouldreallyusethisastheirloginnameunlesssomethingfishyisgoingonthatyouprobablyactuallywanttoprevent@comeonthisisprettynutsright.peoplewithemailaddressesoverfiftycharsdontusethemmuch.com* – MGOwen Oct 27 '17 at 03:57
  • 1
    @MGOwen First, you don't know the purpose of the database, in certain settings someone being denied access because of a frivolous issue like their email being "too long" could be a major issue. Secondly, the link you posted says "The longest valid one is 89", where as this one says it's 62. Which is right? If you just want to pick an arbitrary number or you have a valid reason like the name must be included as part of the address, fine. However it is still reasonable, that when in doubt, you refer to the spec. I still hold that a single person saying "my database maxes at x" is anecdotal. – Mario Oct 30 '17 at 18:18
  • 4
    Longest city name is 'Taumatawhakatangi­hangakoauauotamatea­turipukakapikimaunga­horonukupokaiwhen­uakitanatahu' coming in at 85 characters. https://en.wikipedia.org/wiki/List_of_long_place_names – Michelle Welcks Apr 05 '18 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**. – Grant Miller Jun 22 '18 at 20:46
  • Why not just use VARCHAR(255) for everything? As for email addresses check out this link : https://www.lifewire.com/is-email-address-length-limited-1171110 Originally the standard was 64 characters for the username, 255 characters for the domain name, and one character for the @ sign (320 total). Now it is 254 for the username + the @ sign + the domain name. – Peter Jirak Eldritch May 27 '19 at 16:46
  • "I just queried my database with millions of customers in the USA." - that is commitment to answering a SO question :) – rybo111 Jul 09 '20 at 11:45
  • Can I just say that this is probably the most research I've gone in to an answer where it wasn't code - rock on! – jpgerb Nov 04 '22 at 17:50
191

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..

flu
  • 14,307
  • 8
  • 74
  • 71
Ian Nelson
  • 57,123
  • 20
  • 76
  • 103
  • 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 https://www.justice.gov.uk/guidance/docs/electoral-reg-standards.pdf – Tony R Oct 22 '10 at 20:03
  • 27
    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? – Joseph Redfern Nov 17 '11 at 19:04
  • 1
    It's weird, as it states the Full Name is the title + forename + surname. Which would give 3 * 35 + 2 spaces, so 107 ! Not sure how they got to 70. This looks like pretty out of date information. – Adrian Thompson Phillips Sep 18 '12 at 16:22
  • 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 '12 at 20:12
  • I'm honestly considering putting first and last names in another table and then just referencing it... http://en.wikipedia.org/wiki/Hubert_B._Wolfe_%2B_666,_Sr. – cr0ck3t Jun 01 '15 at 04:58
  • 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 '15 at 08: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._ – Piotr Nawrot Dec 04 '15 at 11:22
78

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.

jrc
  • 20,354
  • 10
  • 69
  • 64
73

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".

Neil McGuigan
  • 46,580
  • 12
  • 123
  • 152
  • 17
    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 '16 at 00: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. – David Metcalfe Oct 03 '21 at 00:47
  • @DavidMetcalfe I see Ghana with 12 chars, incl dash – Neil McGuigan Oct 03 '21 at 05: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? – David Metcalfe Oct 03 '21 at 17:31
  • @DavidMetcalfe see "Use max 12 if storing dash or space" – Neil McGuigan Oct 03 '21 at 18:30
18

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.

Patrick McElhaney
  • 57,901
  • 40
  • 134
  • 167
Kibbee
  • 65,369
  • 27
  • 142
  • 182
  • 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 '10 at 07:48
  • Depends on the implementation. You don't need NVARCHAR if VARCHAR supports UTF-8. – dan04 Dec 22 '10 at 07:10
  • 2
    `[N]Varchar` sizes *do* however, affect your indexes. – RBarryYoung Nov 07 '13 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. :)

BenMorel
  • 34,448
  • 50
  • 182
  • 322
Mike
  • 1,625
  • 16
  • 29
  • 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 http://stackoverflow.com/questions/2340639/why-historically-do-people-use-255-not-256-for-database-field-magnitudes). – Pocketsand May 19 '16 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/

PodTech.io
  • 4,874
  • 41
  • 24
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

Nimantha
  • 6,405
  • 6
  • 28
  • 69
  • 2
    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 03 '16 at 20:26
  • varchar could be a little bit slow. – kta Nov 19 '19 at 05:04
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.

Steve Chambers
  • 37,270
  • 24
  • 156
  • 208
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!).

Loren Charnley
  • 235
  • 4
  • 9
  • 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 03 '21 at 09: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.

kaybenleroll
  • 16,794
  • 16
  • 54
  • 66
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!

ColinYounger
  • 6,735
  • 5
  • 31
  • 33
-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

SQLMenace
  • 132,095
  • 25
  • 206
  • 225