From Sonic Retro

The Somersault was first introduced in Sonic Adventure 2, and also appears in Sonic Advance and Sonic Advance 2. When playing as Sonic or Shadow, if you press B, they will do a somersault that damages enemies. If B is pressed mid-somersault, you can do a combo. Somersaults can be used to get under small openings in doors, to climb steep hills, etc. In Sonic Adventure 2 Sonic and Shadow can get a level-up item called the Flame Ring, which enables the hedgehogs to break steel containers with a "Fire Somersault".

In Sonic Advance 1, the move is a little more involved. Pressing B while moving forward first sends Sonic into a loose spin roll (which can still smash enemies or monitors); pressing B again while in this roll sends him hands-over-feet in a somersault, and pressing B again deploys the Skid Attack, where Sonic can slide feet-first into an opponent. Alternatively, pressing A while in the somersault makes Sonic Backflip into the air.

Sonic Advance 2 dispenses with the three-step approach; pressing B while moving forwards sends Sonic straight head-over-heels into a Skid Attack.