The card security code, sometimes called card verification value (CVV or CVV2) is a term for security features for credit or debit card transactions, providing increased protection for the merchants against credit card fraud. You can correctly identify your CVV number by looking at the back of your credit card and searching for a special 3 digit code. These digits represent your card security code.
Don't mistake your CVV code with your PIN number, you should never enter your PIN number when asked for the CVV.
Banks generate your CVV or CVV2 number when your card is to be issued. The codes are calculated by encrypting the bank card number and the expiration date with secret encryption keys which are known only by the issuing bank. Knowing this, you can generate a seemingly valid number by just inserting any 3 digits onto your testing database. These will obviously fail to pass any validation tests when actually trying to purchase items so you shouldn't even attempt it.
CVV2 is basically just a more secure version of CVV. The algorithm was changed somewhere along the line to be more secure and make sure it couldn't be easily guessed.
To correctly identify your CVV number take a look at the this guide.