It depends on the manufacturer, year, and type of key. The procedure for programming extra keys should be in your owner's manual. What does it say?
I'm guessing that you can't do it on your own without a second functioning key. Usually your best bet is to go to a locksmith. Many of them have access to the programming software that the dealership uses, but charge a fraction of the price.