US outbound: There's no government check. To check in for your flight you will have to show your passport. If you were going to a visa-required country they would insist on finding a proper visa. My understanding is that Spain doesn't require a visa but since I've never been there I can't confirm. The airlines do this check because they don't want to get you there and have to haul you back because you weren't allowed in.
Spain inbound: Never been there but I would assume it's like everyplace else I've been. You will encounter a line of booths of some kind which you must pass between. You show your passport at the booth, you'll almost always get a stamp. (In over 50 international visits I have gotten through without stamps twice. Both times in Singapore and both times because something interfered.) There will in all probability be some piece of paperwork handed out on the plane that you fill out, this official will collect it.
You then reclaim your checked baggage and go through customs. In most places they don't look at those who indicate they have nothing to declare but they do have the right to look at anything they want.
Spain outbound: Never been there but I figure it's like most of the world. It will look very much like it did coming in.
US inbound: You fill out a customs card on the airplane. You get the line of booths as always. I have encountered various ways of handling it so I can't say if it's varied over time or by airport. My recent experience is the passport guy decides if you are going to get further inspection or not. You reclaim your baggage. If you have been selected for additional inspection you then get it. (Note: This is usually over agricultural issues, not that they think you're a smuggler. They can and will take prohibited foodstuffs but so long as you don't lie nor attempt to conceal things there is no penalty beyond the lost stuff. I have seen the woman in front of us get in trouble for "concealment" that I would have considered simply careful packing--she had stuffed stuff inside a shoe. Since she also had similar stuff not hidden I don't think she was actually trying to conceal anything. I do believe she knew the beef was not permitted, though.)
Note that in the US at least you always clear customs at your initial point of entry, you will have to recheck your baggage after this (your bags will already be tagged properly.) I would add an hour above and beyond normal connection times for customs.
So long as you don't look like a bad guy border controls in most of the world are no big deal. The only place that's ever done more than open a bag and glance in is the US and that's agricultural. Even when the guy opened our suitcase and found a big seed pod right on top it wasn't a problem. (We had packed that suitcase in the shade of a big tree and didn't notice the tree's contribution.)
Your looks certainly do matter, though. Many years we stood for 2 hours trying to get into England. The problem was we looked a bit shabby--we had just spent the last 5 months going overland across Africa and our cool-weather clothing had been stolen (the thieves got into the suitcase of things we weren't using, thus the selective nature of the theft), so all we had was our beat-up tropical attire. To compound it we had money-transfer problems, we had a total of $5 (We weren't worried--we had a credit card that would now work.) and it was my mother and I, we didn't know where my father was. (He had had to fly out earlier, then we discovered we couldn't continue with our plans as it was going to be a month before we would have another opportunity to get a plane, so we followed him a few days later instead of a few weeks as intended.) Not only that, but I was 17 and my mother was blind.
We finally got the guy to take the credit card over to the airline and see if they would accept it for tickets onward. When they had no problem with it his tune changed dramatically.