Lithium, sodium and magnesium have attracted wide attention as potential ions for rechargeable batteries. The Materials Project database of high throughput first principles calculations is used to investigate the phase transitions of SnO2 during ion intercalation and extraction. Various intermediate phases are predicted to be formed during the first intercalation, whereas in later cycles other intermediate phases are encountered. The volume expansions after intercalation and extraction are analyzed. We show that different lithium and sodium oxide products found in recent experiments are due to different oxygen chemical potentials.