What is the largest value you can store in a custom field (as meta data for a post)?

The meta value is a LONGTEXT field which can store about 4 GB (gigabytes) of characters (non-binary), but I can’t help you test the limit and note that the number of characters that can be stored will depend on the character encoding.

A quote from MySQL 8.0 Reference Manual:

Note: The four TEXT (data) types are TINYTEXT, TEXT, MEDIUMTEXT, and LONGTEXT.

VARCHAR, VARBINARY, and the BLOB and TEXT types are
variable-length types. For each, the storage requirements depend on
these factors:

  • The actual length of the column value

  • The column’s maximum possible length

  • The character set used for the column, because some character sets contain multibyte characters

For example, a VARCHAR(255) column can hold a string with a maximum
length of 255 characters. Assuming that the column uses the latin1
character set (one byte per character), the actual storage required is
the length of the string (L), plus one byte to record the length
of the string. For the string 'abcd', L is 4 and the storage
requirement is five bytes. If the same column is instead declared to
use the ucs2 double-byte character set, the storage requirement is
10 bytes: The length of 'abcd' is eight bytes and the column
requires two bytes to store lengths because the maximum length is
greater than 255 (up to 510 bytes).

Another quote from the same manual:

The maximum size of a BLOB or TEXT object is determined by its type,
but the largest value you actually can transmit between the client and
server is determined by the amount of available memory and the size of
the communications buffers. … You may also want to compare the
packet sizes and the size of the data objects you are storing with the
storage requirements, see Section 11.7, “Data Type Storage
Requirements”

And actually, the question is more about MySQL/database than WordPress-specific API/function, so Stack Overflow is a better place to get further insights on the largest possible column value for LONGTEXT.

However, just in case it helps, storing a huge number/integer should not be an issue since it’s treated as a string in the database, so for example inserting a PHP_INT_MAX value (which was 9223372036854775807 in my case) worked just fine for me:

add_post_meta( 1, 'foo', PHP_INT_MAX );
$value = get_post_meta( 1, 'foo', true ); // 9223372036854775807
var_dump( PHP_INT_MAX === (int) $value ); // true

References:

Additional Details

( I initially thought you’re asking mainly about the meta key (i.e. name), so I included the following from my original answer. )

The meta key is limited to at most 255 characters (VARCHAR) and if more than that, (in my case) the meta data is not added/saved, regardless in PHP/WordPress (e.g. using add_post_meta()) or a direct SQL command (e.g. via phpMyAdmin).

Sample test case (on WordPress 5.4.2 and MariaDB 10.1 with strict mode not enabled):

// Only the *first* metadata gets added.

$id = add_post_meta( 1, wp_generate_password( 255, false ), 'test' );  // meta key = 255 chars
$id2 = add_post_meta( 1, wp_generate_password( 256, false ), 'test' ); // meta key = 256 chars
var_dump( $id, $id2 ); // int(<meta ID>), bool(false)