When you are in ketosis your body literally burns fat, or rather broken down bits of fat called ketones, instead of sugar. In addition to requiring more energy to make this work, to break down the fat into ketones, it causes a shift that makes your body start using your fat reserves. And your body doesn't store any excess (it actually can't), so any excess fat you literally just pee out. That is how the ketone testing sticks you pee on work. The objective, especially during the beginning of a ketogenic diet, is to completely deplete your glycogen reserves so your body will switch over. This is what causes that lethargic, foggy feeling when you first start keto. Once you are in ketosis however, you can eat carbs so long as you don't eat so many your body switches back over to using sugar. You really need to test your blood to track this and figure out what will and won't knock you out of ketosis. The cheapest I've found the blood test strips is like $1 per strip, so daily testing is pretty pricey. I do it every three days now that I am established in my routine. Also fat just takes more time to digest, so a lot of people feel more satiated for longer on keto diets. Since the #1 reason people struggle with diets is feeling hungry all the time, that makes a big difference.
It doesn't count insoluble fiber. Everything else that is carbs counts.
@BoldW: Nothing wrong with protein powders (so long as they are actually protein, some brands add fillers). Protein has no benefit over a certain point, but you have to eat nearly triple that for it to potentially cause harm in an otherwise healthy person with two kidneys who drinks enough water. But certain people who make their living selling fitness programs and are not doctors or scientists occasionally recommend exactly those levels of excess.
The Myth of 1 g/lb: Optimal Protein Intake for Bodybuilders
There you go. Optimal amounts, references to the actual relevant studies.