On this page of the game guide to Borderlands 2 we have placed the most important information about gaining experience points and advancing to higher experience levels.
In return for completing mission and killing enemies, you will receive experience points. Depending on your current level, mission difficulty and enemies' level, their amount may vary. The bigger the difference, the less (lower level enemies/mission) or more (higher level enemies/mission) experience you will gain. Killing an enemy while driving will additionally lower the amount of points received. A good way of gaining experience is weakening enemies with the vehicle and afterwards killing them on foot.