Installing a smart switch timer - 8 wires in gang box?
Here's the thing.  Wires are NOT color coded for novices.  Actually the color codes mean: 


Red, white, black = this cable has 3 wires + safety ground. 
Black, white - this cable has 2 wires + safety ground. 


There's a rule that white must be used first for neutral and then always-hot, but that's the end of the color coding in North America.  So how do we tell how these go? 

That information is recorded by how they are connected.

And when we get a photo like this, with all the wires splayed out for the camera, that was a misguided choice that leaves us nothing to say but "call an electrician".  There are simply too many possibilities to walk someone through "guessing". 

Fortunately for you, you remember some things that make sense and cross a bunch of possibilities (most) off the list.  

"The neutral wires were all attached together" (from a comment). Whew. Lucky us.   They should all be reconnected together (properly) and pushed into the back of the box.  If you are anticipating needing neutral for a smartswitch, add a pigtail to that bunch of now 4 (this is a job for a red wire nut) and cap off the pigtail for now.  

Now that's off the table. 

The good news is that all remaining wires are hots.  Normally, experimenting is super dangerous, but in this case, they all either connect to each other or to the opposite side of a switch.  Switches connect the 2 terminals, so that means if we connected them all together, your house wouldn't burn down; just a light would be stuck on.

So we need to identify 2 wires in particular out of these 4 hots.  One is supply from the service panel - this is hot at all times.  The other is the switched-hot going up to the lamp.  We can guess that the other wires carry "always-hot" onward to other points of use.  Notably, these points-of-use are now dead.  

There's a "convention" that the red wire is used "preferentially" for a switched-hot, but that's only a common practice, not a standard nor requirement.  

Normally, we crank down super hard on wire nuts - so hard that if the wires went in twisted another way, this un-twists them and twists them the new way.  But for experimentation, just feather-touch them - just enough to hold them together.

Naturally, and I know you already know this, you do all work with the power off, and only turn the power on to test the result of a new configuration. Cap off any wires you are not testing with, even white wires that may be exposed - they can be hot (that's why they have insulation lol).

So anyway I would connect A to B (capping off C and D).  If something that had lost power comes back on again, then either A or B is the always-hot.  Now try A and C.  You quickly find the always-hot.   Once you have that, then keep trying the always-hot with A, C or D until the lamp comes on.  Now you have switched-hot.  

I like to mark switched-hot with red tape and always-hot with black tape (if they aren't already).  This also happens to be the color convention used by most smart switches.  

Then it becomes very straightforward: Join all blacks.  Join all reds. Join all whites. Done!