Basically, here's how it works.
You have an Army, which is made out of X points.
Inside of that army, you can use as many* Detachments as you want, until you reach X points.
Detachments are then formed out of the following:
Combined Arms Detachment is from the main rule book, and is your 'traditional' force organization that you're used to. 1-2 HQ, 2-6 Troops, 0-3 Heavy, 0-3 Fast, 0-3 Elite.
Allied Detachment is also from the main rule book, and normally must be from another faction. This lets you add in a smaller amount of models, just for a 'taste'. This is 1 HQ, 1-2 Troops, 0-1 Heavy, 0-1 Fast, 0-1 Elite. There's a special rule stating that for Space Marines, you can use an Allied Detachment as long as it's a different chapter than other Detachments.
Gladius Detachment: This is the special detachment that Codex: Space Marines just released. It is the core 'super' detachment. Everything chosen in it must come from a single Chapter, and requires at least one Demi-Company Formation, and then one selection from the 'Auxillary' boxes on that page.
Formation Detachments: Formations are everywhere now. Your Codex offers half a dozen of them. Other sourcebooks and web releases have them also. They are identified with 3 skulls in a circle. Each Formation has their own restrictions on what you can play (these are detachments where much of it is dictated for you) and usually have a symbol at the top for specific codexes. (You can't use Blood Angels in a Space Marine detachment, since Blood Angels have their own book).
Basically, you can mix and match until you hit your point cap. As long as every Detachment you use is legal, your entire army is legal and Battle Forged.
You can also choose to play Unbound, which really just says 'throw in whatever you want until you hit your points cap'.
*your local gaming group or tournaments may set restrictions.
EDIT: You can technically put ANY army together using what I've stated above. In the BRB, there's an Ally matrix that tells you how they interact. In general, Marines love each other. But if you decided to add Necrons, double check, they're shifty.