Ask HN: What length do you choose for email fields?

7 points by kondro ↗ HN
I know that the maximum length of email addresses can be 256 characters (http://en.wikipedia.org/wiki/Email_address) however, I always feel dirty about defining varchars with such large bounds and reserving such a large index size for email addresses.

Whilst obviously not in spec, I often set my email fields to 100 characters as I think that even an email address of that size is impracticable for day-to-day usage and should cover off 99.999% of address cases.

So I ask you, how big do you usually make your email address fields?

14 comments

[ 12.1 ms ] story [ 1055 ms ] thread
I use 100 chars, too. No problems to date.
My email fields are usually varchar(128) - which seems like a nice round number to me.
I've seen as low as 64 and as high as 254. I tend to err on the side of spec vs. performance when it comes to this sort of thing.
I tend to err towards 256.

My rationale is this: what percent of the DB will the extra 156 characters take? If I have 1K or less users, an extra 150KB of storage is negligible. If I have 1M users, 150MB is also silly.

I guess, but I don't want to run into the 1KB index size per row limit in MySQL (unless that has changed without me knowing) either and I have other fields I want to index as well.
I seem to remember a spec somewhere detailing that email addresses could be up to 320 characters, and that's what I use. Ensures that I'll never have an issue, yes, but also WAY overkill for most cases, so take with a grain of salt.
To follow exactly the RFC.
254 characters.

From http://www.dominicsayers.com/isemail/:

"Myth: The maximum length of an email address is 320 characters

This arises from the simple arithmetic of maximum length of a domain (255 characters) + maximum length of a mailbox (64 characters) + the @ symbol = 320 characters. Wrong.

This canard is actually documented in the original version of RFC3696. It was corrected in the errata, but nobody reads the errata (except me it would appear).

There's actually a restriction from RFC 5321 on the path element of an SMTP transaction of 256 characters. But this includes angled brackets around the email address, so the maximum length of an email address is 254 characters. You read it here first.

This is not a new restriction - it goes right the way back to RFC 821 and was also in RFC 2821."

I just did a little checking for you over a log of what people try to enter in to an email field in a form:

<5: 1056713 (none or fake)

5-9: 6052

10-19: 226676

20-29: 274956

30-39: 8912

40-49: 196 (from here on they all seem to be either fake or badly formed)

50-59: 29

60-69: 11

70-79: 2

> 80: 0

That's probably not very representative, but it gives you an idea of what people tend to enter in to email fields if you are not too strict about what you accept in the form itself.

So, valid addresses across this sample appear to be between 5 and 39 characters, with the shortest valid address in the log at 8 characters. It's technically possible to have both shorter and longer ones but the chances of those being actual addresses are probably quite low.

All that said, I'd stick with the RFC anyway.

I'm seriously curious why someone would choose a mail address >=30 characters.
Some isps will auto-generate an email address based on the first and lastname of the user + the domain name of the ISP, some corporations do the same. This can get into the +30 characters territory fairly easily.
The company I work for has a policy to take your full name in the local part. So if you are

Juan Alfonso de Borja y Estevez

then by default you'll have a email-address of

juan_alfonso_de_borjy_y_estevez@company.com

This is just the first hit for "long spanish name" I found on google, but I have colleagues that have email-addresses that are that long or (in a few cases) even longer.