The standard for alphabetically sorting Hanyu Pinyin is given in the ABC dictionary series edited by John DeFrancis and issued by the University of Hawaii Press.
Here’s the basic idea:
The ordering is primarily simply alphabetical. Diacritical marks, punctuation, juncture and capitalization are only taken into account when the strings being compared are otherwise identical. For example, píng’ān sorts before pīnyīn, because pingan sorts before pinyin, because g precedes y alphabetically.
Only when two strings are alphabetically identical is non-alphabetical information taken into account.
The series’ Reader’s Guide presents the specifics of the sort order. Since I don’t have to worry about how much space this takes up on my site, I have reformatted the information slightly to give the examples as numbered lists.
Head entry transcriptions with the same sequence of letters are ordered first strictly by letter sequence regardless of tones, then by initial syllable tone in the sequence 0 1 2 3 4. For entries with the same initial tone, arrangement is by the tone of the second syllable, again in the order 0 1 2 3 4. For example:
shīshi
shīshī
shīshí
shīshǐ
shīshì
shíshī
shíshì
shǐshī
shìshī
Irrespective of tones, entries with the vowel u precede those with ü.
For example:
- lú
- lǔ
- lù
- lǘ
- lǚ
- lǜ
- nù
- nǚ
Entries without apostrophe precede those with apostrophe. For example:
- biàn — argue
- bǐ’àn — the other shore
Lower-case entries precede upper-case entries. For example:
- hòujìn — aftereffect
- Hòu Jìn — Later Jin dynasty
For entries with identical spelling, including tones, arrangement is by order of frequency….
For most users, the most important thing to note is that the neutral tone is regarded as 0, not as 5. Thus, the order is not “ā á ǎ à a,” but “a ā á ǎ à.” And, because lowercase comes before uppercase, not “A a Ā ā Á á Ǎ ǎ À à” but “a A ā Ā á Á ǎ Ǎ à À.”
One can see this in action in the A entries for the ABC English-Chinese, Chinese-English Dictionary. And here are some sample pages from an earlier ABC dictionary.
The ABC series follows the example of the Hanyu Pinyin Cihui (汉语拼音词汇 / 漢語拼音詞彙 / Hànyǔ Pīnyīn Cíhuì) (example), with only one minor difference, as noted by Tom Bishop:
HPC [Hanyu Pinyin Cihui] gave hyphens and spaces the same priority as apostrophes, so that lìgōng sorted before lǐ-gōng, in spite of the tones. Usage of hyphens and spaces in pinyin is still far from being fully standardized. (The same is true in English orthography.) Consequently, for collation it makes sense to give less weight to hyphens and spaces, and more weight to tones, thus sorting lǐ-gōng before lìgōng. In ABC, hyphens and spaces don’t affect the sort order unless they change the pronunciation in the same way that apostrophe would; for example, ¹míng-àn 明暗 and ²míng’àn 冥暗 are treated as homophones, and they sort after mǐngǎn 敏感.