Every time someone uses search terms to make a query on Google, an auction takes place between all businesses bidding for related keywords in order for their ads to appear in the search results. This auction determines the ad position and each advertiser's CPC. Two things are important here:
1) The amount you are willing to bid based on your max. CPC.
2) The quality score of your ad based on the specific search query.
Here is a great video, where Hal Varian, Google's chief economist, explains the bidding process in further detail.