Depends what type of carpet it is, as the other answers have said find a piece of carpet from a place where it won't be missed, however if it is patterned make sure you get the right bit first, cut it slightly larger than the damaged bit. If it is a rubber backed carpet ( known as foam backed ) you can use double sided tape, if it is a kind of woven carpet use something like copydex spread around the underneath about half the width of the tape let it dry then again use double sided tape or single sided tape place the tape under the main carpet the feed the new piece in and press it down hard.
Good Luck.