Defence can be really hard to get right, and I remember when I was learning I often felt out of position or didn't know what to do. Here's some concepts that I have thought about, and hopefully might help you. There's a lot to take in, so I recommend reading each one and thinking about it, and don't expect to know all of this immediately. It will take time to internalise, and experience to apply.
---------------------------------------------
1. When your team doesn't have the puck, defend a player. Apply defence to players, don't gravitate towards the puck leaving your player open. If you're not on a player, near a player, or going to a player when defending, you're in the wrong spot.
Short: Defend players, not the puck.
---------------------------------------------
2. What does defending a player mean? Be aware of where they are, where they're going, and be close enough to intercept or at least apply pressure if they get the puck. You don't have to be literally as close as possible, but you need to be close enough to engage them quickly. However, the exception is if you're defending the slot player (right in front of the goalie), you need to be right on top of them and very much disrupting anything they try and do with both your body and stick.
Short: Defend close enough to be threatening, or literally on top of the slot player.
---------------------------------------------
3. Stay alert, keep your head on a swivel, and quickly identify when your teammates are not in their position, or have lost the player they were defending. You may need to switch which player you are defending, and you need to assess which player is the most threat, and if you leave your player whether someone else will defend them.
Short: Switch player if you have to.
---------------------------------------------
4. Try and defend like a group, not individuals. You are three sheepdogs, and they are sheep trying to escape (well, trying to attack, but you get the idea). Know where everyone is and try to work together. Trust your teammates and do your job, cover the player you're supposed to, don't let those sheep pass and get to the goal.
Short: Defend as a group.
---------------------------------------------
5. Be cautious about when to dive in to try and get the puck from a player, ensuring you absolutely know you can get it or you can tie up the player and puck to stop anything happening. If they get around you as you make a dive or big reach and miss, it generally means a free shot. This is especially true when you're the only defender, and against players that might be better than you. Patient defence will reward more often than one big swipe.
Short: Don't over-commit on defence, diving for a puck and missing.
---------------------------------------------
6. When attacking, identify when you're the last person back, and don't move too far forward. Also notice if your last person back has the puck and is making a play, and move yourself back to the redline to be the last person back. This is obviously an attacking strategy, but it is essential to understand that you can't over-commit on offence because it will lead to goals against.
Short: Don't over-commit on offence, recognise if you're the last back, or need to be last back.
---------------------------------------------
7. Defend an incoming player ideally by skating backwards, or otherwise skating sideways, or 45 degrees. Skating directly straight at a player to intercept will often result in them stepping around you. It is similar to over-commiting on defence, you'll be bypassed and out of the play. You are trying to make it difficult for them to get around you, or when they do choose a way to go around you, you are matching speed and skating right with them and not allowing free and open opportunities. The reason you are skating sideways is because you can keep up with an attacker a lot easier from sideways than from stationary or going forward, opposite to their direction.
Short: Approach defence more laterally, not straight.
---------------------------------------------
8. Defend the centre, pushing players to the outside. This is tricky if you're in a 1 on 1 right near the centre face-off, just be in the way and stay in the way. The reason you want players to go outside rather than centre is they have far worse shots (in terms of saveability for a goalie), and far less options.
Short: Defend the centre.
---------------------------------------------
9. What is being in the way? You know that feeling on the street where you nearly run into someone because you can't decide which way to go? Make the players you're defending feel the same thing. Make them question their actions, make them second guess, make them awkward. If they hesitate then you're going to disrupt their attack and get opportunities to get the puck.
Short: Be in the way, make them awkward.
---------------------------------------------
10. In a true 2-on-1, where there is two attacking players left and right that look like they will make an easy pass across and score, go towards and defend the player receiving the pass (the one without the puck). Your goalie is setting up for the first player (with the puck), and has a much higher chance of stopping that first shot compared to stopping a connected cross-field pass and shot. You have to judge quickly whether this is a true 2-on-1, or whether you just defend the puck carrier. It can be tricky to identify all this when under pressure, so just make a decision either way, right or wrong. Goalie will see your decision, see who you're defending, and work with that. Whoever you defend, disrupt them quickly, this is a high risk situation for conceding a goal.
Short: 2-on-1 is hard, pick a player to defend, might not be the one with the puck. Defend quick and hard, and pray.
---------------------------------------------
11. Put more effort into defence than offence. Reducing goals against is the responsiblity of the whole team. This effort is both energy in the game and brain power. Warmups and drills and training spend a lot of time on offence, but the teams that win are the ones with solid defence, with players who just know where to be, and very little confusion whilst defending.
Short: Spend time thinking about defence, it will make you a better player.
---------------------------------------------
Lastly, hockey is one of the hardest sports you can play. Decision making is a huge part of being a better player, and being a better team. You're going to make a hundred decisions per game, and some of them will be wrong. How you react to those wrong decisions will matter just as much as making the right decisions.