GMail Mailbox Size Display – Algorithm Used

Have you ever wondered how the GMail login screen displays the running count of Gmail mailbox size? Like this:

Don’t throw anything away.

Over 5000 megabytes (and counting) of free storage so you’ll never need to delete another message.

The above GMail size display is dynamic using JavaScript. It will be the same as it displays in GMail homepage.

At last today I went through the HTML source code of the page to figure this out. Now I know that GMail size has been increasing 100 MB per month (at least as per their JavaScript!)

Let me go down a bit deep into the technology (JavaScript) details. Sorry, if it bores you!

There is a JavaScript array in the page:

var CP = [ [ 1193122800000, 4321 ],

[ 1199433600000, 6283 ],

[ 2147328000000, 43008 ]];

The first array element is JavaScript time and second element is the storage size in MB expected at that specific time.

1117609200000 means June 01, 2005 and the storage expected was 2250 MB, on July 01, 2005 it was 2350 MB and on August 01, 2005 it is 2450 MB. That is 100 MB per month.

To display the running count, Google uses JavaScript to prorate the storage at the current system time.

I copied the HTML source of this page into a text file and saved as HTML in to my local disk. I wrote the following piece of script just below the CP array declaration.

for (var myDate = new Date(), c = 0; c < CP.length; c++) {


document.write(“Local time: ” + myDate.toLocaleString() + “<br />”);

document.write(“GMail Size: ” + CP[1] + ” MB<br /><hr />”);

Now when you open the HTML in browser, the script prints the output like this:

Local time: Wednesday, June 01, 2005 12:00:00 AM

GMail Size: 2250 MB

Local time: Friday, July 01, 2005 12:00:00 AM

GMail Size: 2350 MB

Local time: Monday, August 01, 2005 12:00:00 AM

GMail Size: 2450 MB

The time here is Pacific Time (Google’s local time)

Here is the code I used for displaying on this blog.

<script type=”text/javascript”><!–
//Script to display running GMAIL inbox size
function updateEmailSize() {
var CP = [ [ 1193122800000, 4321 ], [ 1199433600000, 6283 ], [ 2147328000000, 43008  ]];
var now = (new Date()).getTime();
var quota, i;
if (document.getElementById) {
quota = document.getElementById(“quota”);
} else if (window[“quota”]) {
quota = window[id];
for (i = 0; i < CP.length; i++) {
if (now < CP[i][0]) {
if (i == CP.length) {
quota.innerHTML = ‘Over ‘ + CP[i – 1][1];
} else {
var ts = CP[i – 1][0];
var bs = CP[i – 1][1];
quota.innerHTML = Math.floor(((now-ts) / (CP[i][0]-ts) * (CP[i][1]-bs)) + bs);
// –></script>


  1. But, How it shows continuously change in size on every second? Is it feasible to get the inbox size in one second? then processor must be busy with dong this single task?

    Please reply. May I am wrong but just curious to know more on this..?


  2. As you know, GMail does not provide an option to search emails by size.

    In Gmail, search for the text has:attachment

    This displays all emails having attachments. You may go through ten and delete any unwanted emails.

    Search for and delete any files you would have uploaded using the GMail drive or similar program.

    Another option I can suggest is to create a new account and backup some of your very old emails with attachments to the new id and delete the old ones – Use it as a backup, and you can continue using the old gmail id. Check out my article How to Import All Emails from One Gmail Account to Another? and backup accordingly in the new Gmail acccount.

    Hope this helps.

  3. REspected Sir, 

    My gmail inbox is 97% used of 7 gb and so I am getting warning from gmail for that, Is there anyway in gmail so that I can know which particular emails are taking up too  much of space so I can delete that and make space. 


  4. Hey:

    that’s pretty cool. Is there a way to adapt it to make it work, for example, to increase by exactly 1 every 12 sec. How would you do that?

  5. Hi Jevon,
    A running GMail size counter is present in the page, you could see it in the yellow box. Yes, it’s calculated by interpolating the size like GMail does!

  6. If you’re creative you could make it interpolate the size properly (like GMail does) :o), so instead of displaying the max size, you’d display the actual size…

  7. Yes, that’s right!
    Yesterday Google added 100MB to the counter till 01-Sep-05. That is, now the timestamp 1125558000000 in CP[] array represents 01-Sep-2005 and max mailbox size is 2550 MB.

Leave a Reply

Your email address will not be published.