A measurement of the forward-backward asymmetry A[FB] of oppositely charged lepton pairs (mu mu and e e) produced via Z/gamma* boson exchange in pp collisions at sqrt(s) = 8 TeV is presented. The data sample corresponds to an integrated luminosity of 19.7 inverse femtobarns collected with the CMS detector at the LHC. The measurement of A[FB] is performed for dilepton masses between 40 GeV and 2 TeV and for dilepton rapidity up to 5. The A[FB] measurements as a function of dilepton mass and rapidity are compared with the standard model predictions.