Lawrence Morgan, 19, fought with police officers, headbutting one of them, after he was apprehended outside a bookmakers in February this year.
Police searched him and found a loaded handgun inside his bag, along with cocaine, crack cocaine and heroin.
Morgan has been jailed for five years and eight months at Birmingham Crown Court after admitting possessing a firearm, ammunition and drugs.
Firearms officers examined the weapon and said it was loaded with four rounds of live ammunition.
He was stopped by police during a routine operation at Newtown Shopping Centre on 16 February, West Midlands Police said.
Morgan had initially tried to cycle away from the scene before he was challenged by plain-clothed officers approaching from the opposite direction.
Morgan, of Crompton Close, Nechells, was restrained after a struggle but tried to escape for a second time and headbutted a sergeant.
In a police interview, he denied the assault and claimed he was acting in self defence after the police used excessive force against him.
A charge of assaulting a police officer will remain on file after he admitted the other more serious offences, the court ruled.
Sgt Martin Kelly, said: "The penalties for carrying a loaded gun are severe and rightly so. Anyone who is caught walking around with such a weapon faces a lengthy spell behind bars, as Lawrence Morgan has now found out."
A teenager who was found with a loaded gun in Birmingham has been jailed.