title: Size of notification payload in GCM/FCM
body: <p><strong>This question was originally referring to Google Cloud Messaging (GCM), but now it also applies to the new Firebase Cloud Messaging (FCM) that replaces GCM.</strong></p>
  
  <p>I would like to know how to calculate the size of a GCM payload when it contains a "notification" dictionary.</p>
  
  <p>I have been trying the Google Cloud Messaging service for Android. Some parts of the documentation say you can send up to 4KB of data, and <a href="https://developers.google.com/cloud-messaging/server#notifications_and_data_messages" rel="noreferrer" title="herequot;">here</a> it says "A notification message can have a maximum of 2kb payload".</p>
  
  <p>Doing some tests I could send messages with the "data" payload filled with 4KB of data and the server accepted them without error as expected. </p>
  
  <p>However, using the "notification" payload I found that I could send messages with more than 2KB of data and the server did not return error. I expected such messages would be too big. </p>
  
  <p>I found that the "notification" payload shares the allowed 4KB with the "data" payload, but not in the same way. In the "data" payload, you can calculate the size by adding the size of the keys and values. The "notification" payload takes up more space than the size of the keys and values it contains.</p>
  
  <p>How can I calculate in advance the size of a payload when it contains the "notification" dictionary?</p>