I know, I know. If you're ever loading so many tokens in an email that you're worried about hitting the maximum, you probably need to re-think what you're doing and why. Still - there are some edge cases where some emails might just have a whole lot of tokens. I had a case like this and frustratingly couldn't find a definitive answer to what the limit was - and if there was any. A lot of routes of investigation lead back to this post from 2014 which suggests there is a maximum of 40. Due to its age and lack of concrete sources, I disregarded that and reached out to Marketo support. Turns, out the number 40 is relevant, but it's not an overall limit.
Here's the final word from Marketo support:
This is backed up by my testing. The limit of 40 applies to tokens which pull data from any custom fields on any object, e.g. {{lead.customfield}} or {{company.customfield}}. If it's pulling data from a custom field in your instance, it will count towards the limit of 40. Tokens referring to out-of-the-box fields aren't counted.
Program tokens, regardless of what type they are, are not counted towards the limit. This includes if you have a script token that contains references to custom fields. So you could have a script token that looks at over 40 custom fields across various objects in your instance, and when you load it it should work fine.
This doesn't necessarily mean that you can load infinite program tokens in your email. As you add more, the more load you put on Marketo, and the slower it will run when trying to process your email.
Also, there is a constraint on script tokens which may also be relevant in these edge cases. In this case it's well documented but worth a reminder here: The total size of all script tokens in an email cannot exceed 100kb. This refers to the size of the script when you load it into the script editor - not the size of whatever it outputs. This limit is not per token - it's total. So if you have several weighty script tokens in your email, you may wish to check that they don't cumulatively go over 100kb.
Hopefully that helps and clears up the mystery for the very few people who are curious about it! If anyone has any more insight into this topic or has tips/stories to share, please do so.
But you could reference more than 40 field tokens in a Velocity script, right? 😉
(Yes, yes, I know. Nobody has this problem.)