Ever seen one of these in a town and wanted your own? Look no further, we've got you covered. This can be more or less explained with images, but there'll be an explanation past this, we promise.
This is a Redstone Gate. It opens and closes when you press one of the buttons. A fairly simple contraption to stop other players from getting through that space in your walls you use to get in.
This is what the redstone looks like. Remember to link the torches to each other, then to the lowest fence or iron bar. Additionally, remember to place a roof on your gate before setting this up. Believe us when we say fences can fly if you don't.
Creating a Redstone Gate is fairly simple. First, you sacrifice a goat to the redstone gods. After that, dig down in a line for however long and tall you want the gate to be. The gate shown in this example was five blocks down by four blocks wide, surrounded by Polished Andesite. Any block can be used as a wall block, though don't go too overboard. Use what looks nice, not what looks ridiculous (We're looking at you, ender chest gate).
After you've dug out that space, fill it with one of these:
That's the building part more or less done. Place a button or a lever on both sides of one wall as shown above, and then move to behind where those have been placed. As shown in the second image, you're going to want to link both buttons with redstone, then place a redstone torch on both blocks. Following that, link those torches with the lowest layer of fences or iron bars. The gate should close on its own the first time - this is fine! After that, you're free to open and close it at your leisure.