Figuring out why your dog is scratching the carpet is the first step in stopping the behaviour. Dogs scratch carpet for a number of reasons. If he's scratching in front of the door, he may be trying to tell you he needs a potty break. It may be his instinctive way of trying to make a comfortable bed. It may be that he's just bored or it may be a sign that your dog is suffering from separation anxiety. Whatever the reason, you can likely alter his behaviour.
Hang a set of bells, within dog's nose reach, on the knob of the door through which your dog enters and exits for potty breaks. Each time you take your dog out, ring the jingle bells. Within a few days, your dog will ring the bells when she needs to go outside. If your dog's carpet-scratching is her way of telling you she needs to go outside, giving her this alternate means of communication should alleviate the situation. Jingle bells, such as those sold as Christmas decorations, are good for this purpose.
Buy or make your dog a big, comfortable, cushioned warm bed. Place the bed in the area where your dog most often scratches the carpet. Make sure your dog knows the bed is his. Place some of his favourite treats in or near the bed and praise him when he goes to the bed. If your dog is scratching the carpet as an instinctive response to make a bed for himself, this should stop the behaviour.
Exercise your dog thoroughly. Take your dog for a couple of long walks every day, if at all possible. Many dogs misbehave -- including scratching the carpet -- because they are bored or have pent-up energy. If the dog is tired from having plenty of exercise, she will be less likely to misbehave and scratch the carpet.
Trim your dog's claws regularly. Keep the dog's claws trimmed short. He may be digging in an effort to file down the nails, which would naturally be filed away by digging and walking on hard surfaces in the wild. Trim your dog's nails at home, using a guillotine nail clipper designed for this purpose, or have a veterinarian or groomer trim them.
Evaluate your dog's other behaviours. If the carpet-scratching is accompanied by common symptoms of separation anxiety, consult with your veterinarian, a reputable dog trainer or an animal behaviourist about how to help your dog overcome this condition. Common symptoms of separation anxiety include the dog always being in the room with you, anxiety or nervousness when you are preparing to leave, chewing up items that smell like you while you are away, barking and whining while you are away, destructive behaviour when you are not home, and digging, scratching and chewing if left alone.