How were telephone area codes for different nations decided?

by PCsNBaseball

For example, how did the United States and Canada get +1, but Mexico got +52, and some nations got ones with huge numbers, like Guernsey with +441481?

dh3110

Guernsey is +44 the same as the rest of the UK. 1481 is just the area code