A general rule of thumb is 250 calories, per hour you ride, mostly carbs -- while you are riding.
You also need to eat regularly while riding. Basically, while you are riding you are using up the glucose in your bloodstream, which is the most readily available source of fuel. It doesn't take too long to burn that up; and once it's gone, your body will start using less efficient sources of fuel, including from muscle and fat. If your brain doesn't get enough fuel in time, you will bonk. So, you need to intake calories routinely.
I.e. if you have a huge breakfast, ride 4 hours, have a big lunch, then ride another 4 hours, your body won't be working very efficiently and you risk bonking. You're better off with energy drinks and/or eating (healthy and carb) snacks while riding.