diff --git a/core/core.services.yml b/core/core.services.yml
index 5d01d87667..d15b023f7b 100644
--- a/core/core.services.yml
+++ b/core/core.services.yml
@@ -1528,7 +1528,7 @@ services:
     arguments: ['@event_dispatcher']
   session_configuration:
     class: Drupal\Core\Session\SessionConfiguration
-    arguments: ['%session.storage.options%']
+    arguments: ['@config.factory', '%session.storage.options%']
   session:
     class: Symfony\Component\HttpFoundation\Session\Session
     arguments: ['@session_manager', '@session.attribute_bag', '@session.flash_bag']
diff --git a/core/lib/Drupal/Core/Session/SessionConfiguration.php b/core/lib/Drupal/Core/Session/SessionConfiguration.php
index bbdde7cb5d..c81d7933c0 100644
--- a/core/lib/Drupal/Core/Session/SessionConfiguration.php
+++ b/core/lib/Drupal/Core/Session/SessionConfiguration.php
@@ -2,6 +2,7 @@
 
 namespace Drupal\Core\Session;
 
+use Drupal\Core\Config\ConfigFactoryInterface;
 use Symfony\Component\HttpFoundation\Request;
 
 /**
@@ -14,17 +15,27 @@ class SessionConfiguration implements SessionConfigurationInterface {
    */
   protected $options;
 
+  /**
+   * The session name suffix.
+   *
+   * @var mixed
+   */
+  protected $sessionNameSuffix;
+
   /**
    * Constructs a new session configuration instance.
    *
+   * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
+   *   The configuration factory.
    * @param array $options
    *   An associative array of session ini settings.
    *
    * @see \Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage::__construct()
    * @see http://php.net/manual/session.configuration.php
    */
-  public function __construct($options = []) {
+  public function __construct(ConfigFactoryInterface $config_factory, $options = []) {
     $this->options = $options;
+    $this->sessionNameSuffix = $config_factory->get('system.site')->get('session_name_suffix');
   }
 
   /**
@@ -91,9 +102,12 @@ protected function getUnprefixedName(Request $request) {
       $session_name = $this->options['cookie_domain'];
     }
     else {
-      // Otherwise use $base_url as session name, without the protocol
-      // to use the same session identifiers across HTTP and HTTPS.
-      $session_name = $request->getHost() . $request->getBasePath();
+      // Otherwise use base URL as session name, without the protocol
+      // to use the same session identifiers across HTTP and HTTPS. Session
+      // name suffix is required to clearly distinguish between different
+      // website code bases for example Drupal 7 to Drupal 8 upgrade with
+      // the same host and base path.
+      $session_name = $request->getHost() . $request->getBasePath() . $this->sessionNameSuffix;
       // Replace "core" out of session_name so core scripts redirect properly,
       // specifically install.php.
       $session_name = preg_replace('#/core$#', '', $session_name);
diff --git a/core/modules/system/config/install/system.site.yml b/core/modules/system/config/install/system.site.yml
index d1ab8de7c6..0c779a1199 100644
--- a/core/modules/system/config/install/system.site.yml
+++ b/core/modules/system/config/install/system.site.yml
@@ -2,6 +2,7 @@ uuid: ''
 name: ''
 mail: ''
 slogan: ''
+session_name_suffix: '8'
 page:
   403: ''
   404: ''
diff --git a/core/modules/system/config/schema/system.schema.yml b/core/modules/system/config/schema/system.schema.yml
index e68bbae5a8..36a179efe6 100644
--- a/core/modules/system/config/schema/system.schema.yml
+++ b/core/modules/system/config/schema/system.schema.yml
@@ -41,6 +41,9 @@ system.site:
     default_langcode:
       type: string
       label: 'Site default language code'
+    session_name_suffix:
+      type: string
+      label: 'Site session name suffix'
     mail_notification:
       type: string
       label: 'Notification email address'
diff --git a/core/tests/Drupal/Tests/Core/Session/SessionConfigurationTest.php b/core/tests/Drupal/Tests/Core/Session/SessionConfigurationTest.php
index 70847cb78b..173aadf2c0 100644
--- a/core/tests/Drupal/Tests/Core/Session/SessionConfigurationTest.php
+++ b/core/tests/Drupal/Tests/Core/Session/SessionConfigurationTest.php
@@ -16,10 +16,12 @@ class SessionConfigurationTest extends UnitTestCase {
    *
    * @returns \Drupal\Core\Session\SessionConfiguration|\PHPUnit\Framework\MockObject\MockObject
    */
-  protected function createSessionConfiguration($options = []) {
+  protected function createSessionConfiguration($options = [], $session_name_suffix = NULL) {
+    $stub = $this->getConfigFactoryStub(['system.site' => ['session_name_suffix' => $session_name_suffix]]);
+
     return $this->getMockBuilder('Drupal\Core\Session\SessionConfiguration')
       ->setMethods(['drupalValidTestUa'])
-      ->setConstructorArgs([$options])
+      ->setConstructorArgs([$stub, $options])
       ->getMock();
   }
 
@@ -157,8 +159,8 @@ public function providerTestCookieSecure() {
    *
    * @dataProvider providerTestGeneratedSessionName
    */
-  public function testGeneratedSessionName($uri, $expected_name) {
-    $config = $this->createSessionConfiguration();
+  public function testGeneratedSessionName($uri, $expected_name, $session_name_suffix) {
+    $config = $this->createSessionConfiguration([], $session_name_suffix);
 
     $request = Request::create($uri);
     $options = $config->getOptions($request);
@@ -174,27 +176,27 @@ public function testGeneratedSessionName($uri, $expected_name) {
    */
   public function providerTestGeneratedSessionName() {
     $data = [
-      ['http://example.com/path/index.php', 'SESS', 'example.com'],
-      ['http://www.example.com/path/index.php', 'SESS', 'www.example.com'],
-      ['http://subdomain.example.com/path/index.php', 'SESS', 'subdomain.example.com'],
-      ['http://example.com:8080/path/index.php', 'SESS', 'example.com'],
-      ['https://example.com/path/index.php', 'SSESS', 'example.com'],
-      ['http://example.com/path/core/install.php', 'SESS', 'example.com'],
-      ['http://localhost/path/index.php', 'SESS', 'localhost'],
-      ['http://127.0.0.1/path/index.php', 'SESS', '127.0.0.1'],
-      ['http://127.0.0.1:8888/path/index.php', 'SESS', '127.0.0.1'],
-      ['https://127.0.0.1/path/index.php', 'SSESS', '127.0.0.1'],
-      ['https://127.0.0.1:8443/path/index.php', 'SSESS', '127.0.0.1'],
-      ['http://1.1.1.1/path/index.php', 'SESS', '1.1.1.1'],
-      ['https://1.1.1.1/path/index.php', 'SSESS', '1.1.1.1'],
-      ['http://[::1]/path/index.php', 'SESS', '[::1]'],
-      ['http://[::1]:8888/path/index.php', 'SESS', '[::1]'],
-      ['https://[::1]/path/index.php', 'SSESS', '[::1]'],
-      ['https://[::1]:8443/path/index.php', 'SSESS', '[::1]'],
+      ['http://example.com/path/index.php', 'SESS', 'example.com', NULL],
+      ['http://www.example.com/path/index.php', 'SESS', 'www.example.com', NULL],
+      ['http://subdomain.example.com/path/index.php', 'SESS', 'subdomain.example.com', NULL],
+      ['http://example.com:8080/path/index.php', 'SESS', 'example.com', NULL],
+      ['https://example.com/path/index.php', 'SSESS', 'example.com', NULL],
+      ['http://example.com/path/core/install.php', 'SESS', 'example.com', NULL],
+      ['http://localhost/path/index.php', 'SESS', 'localhost', NULL],
+      ['http://127.0.0.1/path/index.php', 'SESS', '127.0.0.1', NULL],
+      ['http://127.0.0.1:8888/path/index.php', 'SESS', '127.0.0.1', '8'],
+      ['https://127.0.0.1/path/index.php', 'SSESS', '127.0.0.1', '8'],
+      ['https://127.0.0.1:8443/path/index.php', 'SSESS', '127.0.0.1', '8'],
+      ['http://1.1.1.1/path/index.php', 'SESS', '1.1.1.1', '8'],
+      ['https://1.1.1.1/path/index.php', 'SSESS', '1.1.1.1', '8'],
+      ['http://[::1]/path/index.php', 'SESS', '[::1]', '8'],
+      ['http://[::1]:8888/path/index.php', 'SESS', '[::1]', '8'],
+      ['https://[::1]/path/index.php', 'SSESS', '[::1]', '8'],
+      ['https://[::1]:8443/path/index.php', 'SSESS', '[::1]', '8'],
     ];
 
     return array_map(function ($record) {
-      return [$record[0], $record[1] . substr(hash('sha256', $record[2]), 0, 32)];
+      return [$record[0], $record[1] . substr(hash('sha256', $record[2] . $record[3]), 0, 32), $record[3]];
     }, $data);
   }
 
