How to program your 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, and 2009 Mazda B – Series Truck remote keyless entry fob alarm by yourself at home without going to the dealer.
There is even a video below that will show you how this is done!

Turn the ignition from OFF to RUN 8 times within 10 seconds, with the 8th time ending in
All doors will lock then unlock to confirm programming mode.
Within 20 seconds,
press any button on 1st remote transmitter. Door locks will cycle to confirm programming.
Within 20 seconds, press any button on 2nd transmitter (up to 4 transmitters total possible).
Turn the ignition OFF. Locks will again cycle to indicate end of programming mode.