setf is limited to only 8 colors. setaf can set up to 256 colors.
(all the following information will be specific to urxvt, as that is my terminal, but the info will be similar to, if not the same, as other terminals)
Both setf and setaf provide a different escape code. You can view this in the following:
# tput setf 2 | xxd
0000000: 1b5b 3332 6d .[32m
# tput setaf 2 | xxd
0000000: 1b5b 3338 3b35 3b32 6d .[38;5;2m
From my urxvt(7) man page:
"ESC [ Pm m"
Character Attributes (SGR)
...
Pm = 30 / 40 fg/bg Black
Pm = 31 / 41 fg/bg Red
Pm = 32 / 42 fg/bg Green
Pm = 33 / 43 fg/bg Yellow
Pm = 34 / 44 fg/bg Blue
Pm = 35 / 45 fg/bg Magenta
Pm = 36 / 46 fg/bg Cyan
Pm = 37 / 47 fg/bg White
Pm = 38;5 / 48;5 set fg/bg to colour #m (ISO 8613-6)
Thus from the above xxd output, we can see that tput setf 2 uses the Pm = 32, which will set the color to green. tput setaf 2 on the other hand uses the Pm = 38;5, which gets represents the color code defined in ISO 8613-6 (also green).
In ISO 8613-6, colors 0x00-0x07 are the same as the standard colors, and 0x08 - 0x0f are the standard "bold" colors. Once you get to 0x10-0xff you get new colors.
Stolen from wikipedia:
0x00-0x07: standard colors (as in ESC [ 30..37 m)
0x08-0x0f: high intensity colors (as in ESC [ 90..97 m)
0x10-0xe7: 6*6*6=216 colors: 16 + 36*r + 6*g + b (0≤r,g,b≤5)
0xe8-0xff: grayscale from black to white in 24 steps