Open up the Teams.xls sheet from whichever database you are using (Lahman, ArodGarlon, etc) and the historical team id's for each season are listed.
For example here is 1871:
Code:
yearID lgID teamID franchID
1871 NA BS1 BNA
1871 NA CH1 CNA
1871 NA CL1 CFC
1871 NA FW1 KEK
1871 NA NY2 NNA
1871 NA PH1 PNA
1871 NA RC1 ROK
1871 NA TRO TRO
1871 NA WS3 OLY