From Bulbapedia, the community-driven Pokémon encyclopedia.
A Friend Code (Japanese: ともだちコード Friend Code) is a unique twelve-digit code generated once the player has logged onto the Nintendo Wi-Fi Connection on their Wii or DS for the first time. It is used to identify friends for online play.
Each Friend Code differs between games, to make each game have a separate 'identity'. To prevent identity theft, Friend Codes, along with the Wi-Fi ID on a DS, are reset when Wi-Fi Connection is used on another DS. Wi-Fi information can be transferred in the case of replacing an old DS. After registering each other's friend codes, the two people can communicate with each other from any location in the world that has internet. Players with Friend Codes usually have more liberties than players without Friend Codes, some Friend Code exclusive rights being voice chat and co-op play.
The games will not accept all Friend Codes manually entered into the Pal Pad and will display that "The Friend Code is wrong" if a code (i.e. 0000 0000 0000) is not valid.
To register another player's Friend Code, both recipient and transmitter must manually type the other's code in their Pal Pad. This process was created in order to preserve each player's identity and privacy from a person who has the code of the other, but not vice-versa.
An alternative way for registering another's Friend Code, in Pokémon games for the Nintendo DS, the two players can register each other after meeting someone in the Union Room.
In Pokémon Black and White, players can swap friend codes via infrared.
Prior to the April 2011 update, Pokémon Black and White players who have added each other and have met each other online as well on the same game will automatically become neighbors in the Pokémon Dream World.